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([])
11 self.assertEqual(board.export(), {
17 'board_locations': {},
18 'player': board.player.export(),
21 def test_lose_health(self):
22 board = GameBoard.new_game([])
23 self.assertEqual(board.health, 4)
24 state_1 = board.export()
27 self.assertEqual(board.health, 3)
28 state_2 = board.export()
30 # Make sure nothing else has changed.
33 self.assertEqual(state_1, state_2)
36 class TestLocationCard(TestCase):
37 def test_generate_bitwise_operand(self):
38 # This is testing a random process, so it may fail occasionally.
41 operand_sets.append(LocationCard.generate_bitwise_operand())
44 for operand_set in operand_sets:
45 sizes[len(operand_set)] += 1
46 bits.update(operand_set)
47 # TODO: Test that there's at least one condition and one direction.
48 self.assertTrue(sizes[2] > 0)
49 self.assertTrue(sizes[3] > 0)
50 self.assertTrue(sizes[2] > sizes[3])
51 self.assertEqual(bits, set(BITS.values()))
53 def test_new_location_no_actions(self):
54 location = LocationCard.new_location({'actions': []})
55 self.assertEqual(location.actions, [])
57 def test_new_location_one_action(self):
58 location = LocationCard.new_location({'actions': [
59 {'required_bits': [], 'action_class': 'DoNothing'},
61 [action] = location.actions
62 self.assertEqual(type(action), actions.DoNothing)
63 self.assertEqual(action.required_bits, set())