Choose locations for the board.
[naja.git] / naja / tests / test_actions.py
index 3d3a58ea63346c936ebfb2b1c8a619640dbb5d87..d2c723a6b4082c0135da73565a44d0862afab361 100644 (file)
@@ -10,6 +10,14 @@ class TestActions(TestCase):
     def make_player(self, *bits):
         return Player(sum(1 << bit for bit in bits), None)
 
+    def make_board(self, player_bits=None, locations=None):
+        if locations is None:
+            locations = [{'actions': []}]
+        board = GameBoard.new_game(locations)
+        if player_bits is not None:
+            board.player.bits.set_bits(player_bits)
+        return board
+
     def test_check_available(self):
         def check_available(action_bits, player_bits, expected_result):
             action = actions.LocationAction(action_bits)
@@ -22,14 +30,14 @@ class TestActions(TestCase):
         check_available(set([BITS.MSB]), [BITS.MSB], True)
 
     def test_DoNothing(self):
-        board = GameBoard.new_game([])
+        board = self.make_board()
         state_before = board.export()
         actions.DoNothing(set()).perform_action(board, None)
         state_after = board.export()
         self.assertEqual(state_before, state_after)
 
     def test_LoseHealthOrMSB_MSB_clear(self):
-        board = GameBoard.new_game([])
+        board = self.make_board()
         state_before = board.export()
         actions.LoseHeathOrMSB(set()).perform_action(board, None)
         state_after = board.export()
@@ -40,8 +48,7 @@ class TestActions(TestCase):
         self.assertEqual(state_before, state_after)
 
     def test_LoseHealthOrMSB_MSB_set(self):
-        board = GameBoard.new_game([])
-        board.player.bits.set_bit(BITS.MSB)
+        board = self.make_board(player_bits=[BITS.MSB])
         state_before = board.export()
         actions.LoseHeathOrMSB(set()).perform_action(board, None)
         state_after = board.export()
@@ -52,7 +59,7 @@ class TestActions(TestCase):
         self.assertEqual(state_before, state_after)
 
     def test_SetBits(self):
-        board = GameBoard.new_game([])
+        board = self.make_board()
         state_before = board.export()
         location = LocationCard(set([BITS.MSB, BITS.NORTH]), [])
         actions.SetBits(set()).perform_action(board, location)
@@ -65,8 +72,7 @@ class TestActions(TestCase):
         self.assertEqual(state_before, state_after)
 
     def test_ToggleBits(self):
-        board = GameBoard.new_game([])
-        board.player.bits.set_bit(BITS.NORTH)
+        board = self.make_board(player_bits=[BITS.NORTH])
         state_before = board.export()
         location = LocationCard(set([BITS.MSB, BITS.NORTH]), [])
         actions.ToggleBits(set()).perform_action(board, location)