Game state management.
[naja.git] / naja / tests / test_gameboard.py
1 from unittest import TestCase
2
3 from naja.constants import BITS
4 from naja.gameboard import GameBoard, LocationCard
5
6
7 class TestGameBoard(TestCase):
8     def test_export_new_board(self):
9         board = GameBoard(None, 4, 4)
10         self.assertEqual(board.export(), {
11             'max_health': 4,
12             'health': 4,
13             'wins_required': 4,
14             'wins': 0,
15             'locations': {},
16         })
17
18     def test_lose_health(self):
19         board = GameBoard(None, 4, 4)
20         self.assertEqual(board.health, 4)
21         state_1 = board.export()
22
23         board.lose_health()
24         self.assertEqual(board.health, 3)
25         state_2 = board.export()
26
27         # Make sure nothing else has changed.
28         state_1.pop('health')
29         state_2.pop('health')
30         self.assertEqual(state_1, state_2)
31
32
33 class TestLocationCard(TestCase):
34     def test_generate_bitwise_operand(self):
35         # This is testing a random process, so it may fail occasionally.
36         operand_sets = []
37         for _ in range(100):
38             operand_sets.append(LocationCard.generate_bitwise_operand())
39         sizes = {2: 0, 3: 0}
40         bits = set()
41         for operand_set in operand_sets:
42             sizes[len(operand_set)] += 1
43             bits.update(operand_set)
44             # TODO: Test that there's at least one condition and one direction.
45         self.assertTrue(sizes[2] > 0)
46         self.assertTrue(sizes[3] > 0)
47         self.assertTrue(sizes[2] > sizes[3])
48         self.assertEqual(bits, set(BITS.values()))