X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Ftests%2Ftest_actions.py;h=d770f12397f04ffec487192ba299a8445f51a3a1;hb=db97008646152ce2d93949e0266635fdd89a0b91;hp=3497ee49c6a47d7971e5e67f3b1ca03ebbf1be42;hpb=7ce574e6d8521f74fab9ca65847a49492c5783b5;p=naja.git diff --git a/naja/tests/test_actions.py b/naja/tests/test_actions.py index 3497ee4..d770f12 100644 --- a/naja/tests/test_actions.py +++ b/naja/tests/test_actions.py @@ -1,12 +1,16 @@ from unittest import TestCase -from naja.constants import BITS +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: @@ -16,7 +20,7 @@ class TestActions(TestCase): def make_board(self, player_bits=None, locations=None): if locations is None: locations = [{'actions': []}] - board = GameBoard.new_game(locations) + board = GameBoard.new_game({'cards': locations}) if player_bits is not None: board.player.bits.bits = 0 board.player.bits.set_bits(player_bits) @@ -50,9 +54,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() @@ -164,3 +191,24 @@ class TestActions(TestCase): 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)