from naja.constants import BITS, MOVES
from naja.gameboard import GameBoard, LocationCard
+from naja.options import parse_args
from naja.player import Player
from naja import actions
class TestActions(TestCase):
+ def setUp(self):
+ parse_args([])
+
def make_player(self, *bits):
player_bits = 0
for bit in bits:
def make_board(self, player_bits=None, locations=None):
if locations is None:
- locations = [{'actions': []}]
- board = GameBoard.new_game(locations)
+ locations = [{'card_name': 'card', 'actions': []}]
+ board = GameBoard.new_game({'cards': locations})
if player_bits is not None:
board.player.bits.bits = 0
board.player.bits.set_bits(player_bits)
return board
+ def make_location_card(self, bits=(), name='card', actions=()):
+ return LocationCard(name, set(bits), list(actions), None)
+
def assert_player_bits(self, board, *bits):
self.assertEqual(sum(1 << bit for bit in bits), board.player.bits.bits)
def test_SetBits(self):
board = self.make_board()
state_before = board.export()
- card = LocationCard(set([BITS.MSB, BITS.NORTH]), [])
+ card = self.make_location_card([BITS.MSB, BITS.NORTH])
actions.SetBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(
def test_ToggleBits(self):
board = self.make_board(player_bits=[BITS.NORTH])
state_before = board.export()
- card = LocationCard(set([BITS.MSB, BITS.NORTH]), [])
+ card = self.make_location_card([BITS.MSB, BITS.NORTH])
actions.ToggleBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(board.player.bits.check_bit(BITS.MSB), True)
def test_LoseHealthOrMSBAndSetBits_MSB_clear(self):
board = self.make_board(player_bits=[])
state_before = board.export()
- card = LocationCard(set([BITS.BLUE, BITS.NORTH]), [])
+ card = self.make_location_card([BITS.BLUE, BITS.NORTH])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] - 1)
def test_LoseHealthOrMSBAndSetBits_MSB_set(self):
board = self.make_board(player_bits=[BITS.MSB])
state_before = board.export()
- card = LocationCard(set([BITS.BLUE, BITS.NORTH]), [])
+ card = self.make_location_card([BITS.BLUE, BITS.NORTH])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assert_player_bits(board, BITS.BLUE, BITS.NORTH)
def test_LoseHealthOrMSBAndSetBits_MSB_set_and_on_card(self):
board = self.make_board(player_bits=[BITS.MSB])
state_before = board.export()
- card = LocationCard(set([BITS.MSB, BITS.NORTH]), [])
+ card = self.make_location_card([BITS.MSB, BITS.NORTH])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assert_player_bits(board, BITS.MSB, BITS.NORTH)
board = self.make_board(player_bits=[BITS.NORTH])
board.lose_health()
state_before = board.export()
- card = LocationCard(set([BITS.BLUE, BITS.NORTH]), [])
+ card = self.make_location_card([BITS.BLUE, BITS.NORTH])
actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] + 1)
board = self.make_board(player_bits=[BITS.MSB, BITS.NORTH])
board.lose_health()
state_before = board.export()
- card = LocationCard(set([BITS.BLUE, BITS.NORTH]), [])
+ card = self.make_location_card([BITS.BLUE, BITS.NORTH])
actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] + 1)
def test_AllowKnightMove(self):
board = self.make_board(player_bits=[BITS.RED, BITS.BLUE])
- actions.AllowChessMove(set([BITS.RED, BITS.BLUE]), chesspiece="KNIGHT").perform_action(board, None)
+ actions.AllowChessMove(
+ set([BITS.RED, BITS.BLUE]), chesspiece="KNIGHT"
+ ).perform_action(board, None)
self.assertEqual(board.player.movement_mode, MOVES.KNIGHT)
-
def test_AllowBishopMove(self):
board = self.make_board(player_bits=[BITS.RED, BITS.BLUE])
- actions.AllowChessMove(set([BITS.RED, BITS.BLUE]), chesspiece="BISHOP").perform_action(board, None)
+ actions.AllowChessMove(
+ set([BITS.RED, BITS.BLUE]), chesspiece="BISHOP"
+ ).perform_action(board, None)
self.assertEqual(board.player.movement_mode, MOVES.BISHOP)
-
def test_AllowCastleMove(self):
board = self.make_board(player_bits=[BITS.RED, BITS.BLUE])
- actions.AllowChessMove(set([BITS.RED, BITS.BLUE]), chesspiece="CASTLE").perform_action(board, None)
+ actions.AllowChessMove(
+ set([BITS.RED, BITS.BLUE]), chesspiece="CASTLE"
+ ).perform_action(board, None)
self.assertEqual(board.player.movement_mode, MOVES.CASTLE)