1 from unittest import TestCase
3 from naja.constants import BITS
4 from naja.gameboard import GameBoard
5 from naja.player import Player
6 from naja import actions
9 class TestActions(TestCase):
10 def make_player(self, *bits):
11 return Player(sum(1 << bit for bit in bits), None)
13 def test_check_available(self):
14 def check_available(action_bits, player_bits, expected_result):
15 action = actions.LocationAction(action_bits)
16 player = self.make_player(*player_bits)
17 self.assertEqual(action.check_available(player), expected_result)
19 check_available(set(), [], True)
20 check_available(set(), [BITS.MSB], True)
21 check_available(set([BITS.MSB]), [], False)
22 check_available(set([BITS.MSB]), [BITS.MSB], True)
24 def test_DoNothing(self):
25 board = GameBoard.new_game([])
26 state_before = board.export()
27 actions.DoNothing(set()).perform_action(board)
28 state_after = board.export()
29 self.assertEqual(state_before, state_after)
31 def test_LoseHealthOrMSB_MSB_clear(self):
32 board = GameBoard.new_game([])
33 state_before = board.export()
34 actions.LoseHeathOrMSB(set()).perform_action(board)
35 state_after = board.export()
36 self.assertEqual(state_after['health'], state_before['health'] - 1)
38 state_before.pop('health')
39 state_after.pop('health')
40 self.assertEqual(state_before, state_after)