X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Ftests%2Ftest_actions.py;h=f590caa9e576adf99e6cb1ab9dbebd3dda15e498;hb=c100c349d722cd81b8aea015ae09b1627ca67883;hp=a8d9201206425be0840bbad3a947965c858d8179;hpb=4430c92a3e7c1cd14a5a672c4899ee5406a095fb;p=naja.git diff --git a/naja/tests/test_actions.py b/naja/tests/test_actions.py index a8d9201..f590caa 100644 --- a/naja/tests/test_actions.py +++ b/naja/tests/test_actions.py @@ -1,6 +1,6 @@ from unittest import TestCase -from naja.constants import BITS +from naja.constants import BITS, MOVES from naja.gameboard import GameBoard, LocationCard from naja.player import Player from naja import actions @@ -50,9 +50,32 @@ class TestActions(TestCase): check_available(set([BITS.MSB]), [], False) check_available(set([BITS.MSB]), [BITS.MSB], True) - def test_bits_translation(self): - action = actions.LocationAction(set([BITS.NORTH, 'MSB'])) - self.assertEqual(action.required_bits, set([BITS.NORTH, BITS.MSB])) + def test_get_text(self): + class LocationAction1(actions.LocationAction): + TEXT = "foo" + action1 = LocationAction1([]) + self.assertEqual(action1.get_text(), "foo") + + class LocationAction2(actions.LocationAction): + TEXT = "foo %(bar)s" + action2 = LocationAction2([], bar="baz") + self.assertEqual(action2.get_text(), "foo baz") + + def test_get_text_row_column(self): + class DirectionAction(actions.LocationAction): + TEXT = "foo %(direction)s %(rowcol)s" + + action_north = DirectionAction([], direction='NORTH') + self.assertEqual(action_north.get_text(), "foo NORTH column") + + action_south = DirectionAction([], direction='SOUTH') + self.assertEqual(action_south.get_text(), "foo SOUTH column") + + action_east = DirectionAction([], direction='EAST') + self.assertEqual(action_east.get_text(), "foo EAST row") + + action_west = DirectionAction([], direction='WEST') + self.assertEqual(action_west.get_text(), "foo WEST row") def test_DoNothing(self): board = self.make_board() @@ -100,11 +123,11 @@ class TestActions(TestCase): def test_LoseHealthOrMSBAndSetBits_MSB_clear(self): board = self.make_board(player_bits=[]) state_before = board.export() - card = LocationCard(set([BITS.CYAN, BITS.NORTH]), []) + card = LocationCard(set([BITS.BLUE, BITS.NORTH]), []) actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card) state_after = board.export() self.assertEqual(state_after['health'], state_before['health'] - 1) - self.assert_player_bits(board, BITS.CYAN, BITS.NORTH) + self.assert_player_bits(board, BITS.BLUE, BITS.NORTH) self.assert_state( state_before, state_after, exclude=['health'], player_exclude=['bits']) @@ -112,10 +135,10 @@ 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.CYAN, BITS.NORTH]), []) + card = LocationCard(set([BITS.BLUE, BITS.NORTH]), []) actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card) state_after = board.export() - self.assert_player_bits(board, BITS.CYAN, BITS.NORTH) + self.assert_player_bits(board, BITS.BLUE, BITS.NORTH) self.assert_state(state_before, state_after, player_exclude=['bits']) def test_LoseHealthOrMSBAndSetBits_MSB_set_and_on_card(self): @@ -129,7 +152,7 @@ class TestActions(TestCase): def test_AcquireWinToken(self): board = self.make_board( - player_bits=[BITS.CYAN, BITS.MAGENTA, BITS.YELLOW, BITS.MSB]) + player_bits=[BITS.RED, BITS.GREEN, BITS.BLUE]) state_before = board.export() actions.AcquireWinToken(set()).perform_action(board, None) state_after = board.export() @@ -138,3 +161,46 @@ class TestActions(TestCase): self.assert_state( state_before, state_after, exclude=['wins'], player_exclude=['bits']) + + def test_GainHealthAndClearBitsOrMSB_MSB_clear(self): + board = self.make_board(player_bits=[BITS.NORTH]) + board.lose_health() + state_before = board.export() + card = LocationCard(set([BITS.BLUE, BITS.NORTH]), []) + actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card) + state_after = board.export() + self.assertEqual(state_after['health'], state_before['health'] + 1) + self.assert_player_bits(board) + self.assert_state( + state_before, state_after, exclude=['health'], + player_exclude=['bits']) + + def test_GainHealthAndClearBitsOrMSB_MSB_set(self): + board = self.make_board(player_bits=[BITS.MSB, BITS.NORTH]) + board.lose_health() + state_before = board.export() + card = LocationCard(set([BITS.BLUE, BITS.NORTH]), []) + actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card) + state_after = board.export() + self.assertEqual(state_after['health'], state_before['health'] + 1) + self.assert_player_bits(board, BITS.NORTH) + self.assert_state( + state_before, state_after, exclude=['health'], + player_exclude=['bits']) + + 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) + 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) + 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) + self.assertEqual(board.player.movement_mode, MOVES.CASTLE)