1 from unittest import TestCase
3 from naja.constants import BITS
4 from naja.gameboard import GameBoard, LocationCard
5 from naja import actions
8 class TestGameBoard(TestCase):
9 def test_export_new_board(self):
10 board = GameBoard.new_game([{'actions': []}])
11 exported_state = board.export()
12 board_locations = exported_state.pop('board_locations')
13 self.assertEqual(exported_state, {
18 'locations': [{'actions': []}],
19 'player': board.player.export(),
22 set(board_locations.keys()),
23 set((x, y) for x in range(5) for y in range(5)))
24 for location_state in board_locations.values():
26 sorted(location_state.keys()), ['actions', 'bitwise_operand'])
27 self.assertEqual(location_state['actions'], [])
28 self.assertTrue(2 <= len(location_state['bitwise_operand']) <= 3)
30 def test_lose_health(self):
31 board = GameBoard.new_game([{'actions': []}])
32 self.assertEqual(board.health, 4)
33 state_1 = board.export()
36 self.assertEqual(board.health, 3)
37 state_2 = board.export()
39 # Make sure nothing else has changed.
42 self.assertEqual(state_1, state_2)
45 class TestLocationCard(TestCase):
46 def test_generate_bitwise_operand(self):
47 # This is testing a random process, so it may fail occasionally.
50 operand_sets.append(LocationCard.generate_bitwise_operand())
53 for operand_set in operand_sets:
54 sizes[len(operand_set)] += 1
55 bits.update(operand_set)
56 # TODO: Test that there's at least one condition and one direction.
57 self.assertTrue(sizes[2] > 0)
58 self.assertTrue(sizes[3] > 0)
59 self.assertTrue(sizes[2] > sizes[3])
60 self.assertEqual(bits, set(BITS.values()))
62 def test_new_location_no_actions(self):
63 location = LocationCard.new_location({'actions': []})
64 self.assertEqual(location.actions, [])
66 def test_new_location_one_action(self):
67 location = LocationCard.new_location({'actions': [
68 {'required_bits': [], 'action_class': 'DoNothing'},
70 [action] = location.actions
71 self.assertEqual(type(action), actions.DoNothing)
72 self.assertEqual(action.required_bits, set())