X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Ftests%2Ftest_actions.py;h=b233df76adc709c73ac0ea31570f9b20cc40cc84;hb=0b43a81c2816278ea23e97a41a5cfc7473b4b054;hp=14d5f0e6e2f8efd56b3f926c510ce94ea2003dfe;hpb=a455a8ce46afe31f217e0a8fe8d0247d28eed8ad;p=naja.git diff --git a/naja/tests/test_actions.py b/naja/tests/test_actions.py index 14d5f0e..b233df7 100644 --- a/naja/tests/test_actions.py +++ b/naja/tests/test_actions.py @@ -2,11 +2,15 @@ from unittest import TestCase 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: @@ -15,13 +19,16 @@ class TestActions(TestCase): 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) @@ -103,7 +110,7 @@ class TestActions(TestCase): 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( @@ -113,7 +120,7 @@ class TestActions(TestCase): 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) @@ -123,7 +130,7 @@ class TestActions(TestCase): 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) @@ -135,7 +142,7 @@ class TestActions(TestCase): 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) @@ -144,7 +151,7 @@ class TestActions(TestCase): 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) @@ -166,7 +173,7 @@ class TestActions(TestCase): 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) @@ -179,7 +186,7 @@ class TestActions(TestCase): 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) @@ -190,17 +197,21 @@ class TestActions(TestCase): 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)