X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Ftests%2Ftest_actions.py;h=3d3a58ea63346c936ebfb2b1c8a619640dbb5d87;hb=e3f865facdb9c4b3b94c1b89d0734ed09fd6b205;hp=8896b8d2607e72a6bc0ac034fba8b7f2a2a75f66;hpb=18eaa15b16160df3dcd23dd2773603d1f2e179ce;p=naja.git diff --git a/naja/tests/test_actions.py b/naja/tests/test_actions.py index 8896b8d..3d3a58e 100644 --- a/naja/tests/test_actions.py +++ b/naja/tests/test_actions.py @@ -1,5 +1,7 @@ from unittest import TestCase +from naja.constants import BITS +from naja.gameboard import GameBoard, LocationCard from naja.player import Player from naja import actions @@ -8,12 +10,70 @@ class TestActions(TestCase): def make_player(self, *bits): return Player(sum(1 << bit for bit in bits), None) - def test_DoNothing_check_available(self): - player = self.make_player() - action = actions.DoNothing(set()) - self.assertEqual(action.check_available(player), True) + def test_check_available(self): + def check_available(action_bits, player_bits, expected_result): + action = actions.LocationAction(action_bits) + player = self.make_player(*player_bits) + self.assertEqual(action.check_available(player), expected_result) - def test_LoseHealthOrMSB_check_available(self): - player = self.make_player() - action = actions.LoseHeathOrMSB(set()) - self.assertEqual(action.check_available(player), True) + check_available(set(), [], True) + check_available(set(), [BITS.MSB], True) + check_available(set([BITS.MSB]), [], False) + check_available(set([BITS.MSB]), [BITS.MSB], True) + + def test_DoNothing(self): + board = GameBoard.new_game([]) + state_before = board.export() + actions.DoNothing(set()).perform_action(board, None) + state_after = board.export() + self.assertEqual(state_before, state_after) + + def test_LoseHealthOrMSB_MSB_clear(self): + board = GameBoard.new_game([]) + state_before = board.export() + actions.LoseHeathOrMSB(set()).perform_action(board, None) + state_after = board.export() + self.assertEqual(state_after['health'], state_before['health'] - 1) + + state_before.pop('health') + state_after.pop('health') + self.assertEqual(state_before, state_after) + + def test_LoseHealthOrMSB_MSB_set(self): + board = GameBoard.new_game([]) + board.player.bits.set_bit(BITS.MSB) + state_before = board.export() + actions.LoseHeathOrMSB(set()).perform_action(board, None) + state_after = board.export() + self.assertEqual(board.player.bits.check_bit(BITS.MSB), False) + + state_before['player'].pop('bits') + state_after['player'].pop('bits') + self.assertEqual(state_before, state_after) + + def test_SetBits(self): + board = GameBoard.new_game([]) + state_before = board.export() + location = LocationCard(set([BITS.MSB, BITS.NORTH]), []) + actions.SetBits(set()).perform_action(board, location) + state_after = board.export() + self.assertEqual( + board.player.bits.check_bits([BITS.MSB, BITS.NORTH]), True) + + state_before['player'].pop('bits') + state_after['player'].pop('bits') + self.assertEqual(state_before, state_after) + + def test_ToggleBits(self): + board = GameBoard.new_game([]) + board.player.bits.set_bit(BITS.NORTH) + state_before = board.export() + location = LocationCard(set([BITS.MSB, BITS.NORTH]), []) + actions.ToggleBits(set()).perform_action(board, location) + state_after = board.export() + self.assertEqual(board.player.bits.check_bit(BITS.MSB), True) + self.assertEqual(board.player.bits.check_bit(BITS.NORTH), False) + + state_before['player'].pop('bits') + state_after['player'].pop('bits') + self.assertEqual(state_before, state_after)