Save game.
[naja.git] / naja / tests / test_gameboard.py
index d843c7e9fc86e2cee5e913551c08946f3f9f8d31..e3aa32e03be48a27e0da319219fa880e25491c77 100644 (file)
@@ -21,10 +21,15 @@ class TestGameBoard(TestCase):
         self.assertEqual(state1, state2)
 
     def test_export_new_board(self):
-        board = GameBoard.new_game([{'actions': [{
-            'action_class': 'LoseHealthOrMSB',
-            'required_bits': [],
-        }]}])
+        board = GameBoard.new_game([{'actions': [
+            {
+                'action_class': 'LoseHealthOrMSB',
+                'required_bits': [],
+            }, {
+                'action_class': 'GainHealth',
+                'required_bits': [BITS.RED],
+            },
+        ]}])
         exported_state = board.export()
         board_locations = exported_state.pop('board_locations')
         self.assertEqual(exported_state, {
@@ -32,24 +37,36 @@ class TestGameBoard(TestCase):
             'health': 4,
             'wins_required': 4,
             'wins': 0,
-            'locations': [{'actions': [{
-                'action_class': 'LoseHealthOrMSB',
-                'required_bits': [],
-            }]}],
+            'locations': [{'actions': [
+                {
+                    'action_class': 'LoseHealthOrMSB',
+                    'required_bits': [],
+                }, {
+                    'action_class': 'GainHealth',
+                    'required_bits': [BITS.RED],
+                },
+            ]}],
             'player': board.player.export(),
         })
-        self.assertEqual(
-            set(board_locations.keys()),
-            set((x, y) for x in range(5) for y in range(5)))
-        for location_state in board_locations.values():
+        positions = []
+        for position, location_state in board_locations:
+            positions.append(position)
             self.assertEqual(
                 sorted(location_state.keys()), ['actions', 'bitwise_operand'])
-            self.assertEqual(location_state['actions'], [{
-                'action_class': 'LoseHealthOrMSB',
-                'required_bits': [],
-                'data': {},
-            }])
+            self.assertEqual(location_state['actions'], [
+                {
+                    'action_class': 'LoseHealthOrMSB',
+                    'required_bits': [],
+                    'data': {},
+                }, {
+                    'action_class': 'GainHealth',
+                    'required_bits': [BITS.RED],
+                    'data': {},
+                },
+            ])
             self.assertTrue(2 <= len(location_state['bitwise_operand']) <= 3)
+        self.assertEqual(
+            positions, sorted((x, y) for x in range(5) for y in range(5)))
 
     def test_lose_health(self):
         board = GameBoard.new_game([{'actions': []}])