added more tests for chess moves; they all pass
authoradrianna <adrianna.pinska@gmail.com>
Fri, 16 May 2014 08:56:38 +0000 (10:56 +0200)
committeradrianna <adrianna.pinska@gmail.com>
Fri, 16 May 2014 08:56:51 +0000 (10:56 +0200)
naja/tests/test_actions.py
naja/tests/test_gameboard.py
naja/tests/test_player.py

index e8be3c8ca8dd60c98b728e97b52f640a938f4dee..f590caa9e576adf99e6cb1ab9dbebd3dda15e498 100644 (file)
@@ -1,6 +1,6 @@
 from unittest import TestCase
 
-from naja.constants import BITS
+from naja.constants import BITS, MOVES
 from naja.gameboard import GameBoard, LocationCard
 from naja.player import Player
 from naja import actions
@@ -187,3 +187,20 @@ class TestActions(TestCase):
         self.assert_state(
             state_before, state_after, exclude=['health'],
             player_exclude=['bits'])
+
+    def test_AllowKnightMove(self):
+        board = self.make_board(player_bits=[BITS.RED, BITS.BLUE])
+        actions.AllowChessMove(set([BITS.RED, BITS.BLUE]), chesspiece="KNIGHT").perform_action(board, None)
+        self.assertEqual(board.player.movement_mode, MOVES.KNIGHT)
+
+
+    def test_AllowBishopMove(self):
+        board = self.make_board(player_bits=[BITS.RED, BITS.BLUE])
+        actions.AllowChessMove(set([BITS.RED, BITS.BLUE]), chesspiece="BISHOP").perform_action(board, None)
+        self.assertEqual(board.player.movement_mode, MOVES.BISHOP)
+
+
+    def test_AllowCastleMove(self):
+        board = self.make_board(player_bits=[BITS.RED, BITS.BLUE])
+        actions.AllowChessMove(set([BITS.RED, BITS.BLUE]), chesspiece="CASTLE").perform_action(board, None)
+        self.assertEqual(board.player.movement_mode, MOVES.CASTLE)
index d40873f12e707e78ef04a34e5322564c2812ed28..3bbf59bcf6e21d8cc916e37079c5a19eb04ebdbe 100644 (file)
@@ -1,6 +1,6 @@
 from unittest import TestCase
 
-from naja.constants import BITS
+from naja.constants import BITS, MOVES
 from naja.gameboard import GameBoard, LocationCard
 from naja import actions
 
@@ -124,6 +124,25 @@ class TestGameBoard(TestCase):
             (0, 2): '12', (1, 2): '32', (3, 2): '42', (4, 2): '02',
         }))
 
+    def test_allow_chess_move_knight(self):
+        board = GameBoard.new_game([{'actions': []}])
+        board.board_locations = self.generate_locations()
+        board.allow_chess_move(MOVES.KNIGHT)
+        self.assertEqual(board.player.movement_mode, MOVES.KNIGHT)
+
+    def test_allow_chess_move_bishop(self):
+        board = GameBoard.new_game([{'actions': []}])
+        board.board_locations = self.generate_locations()
+        board.allow_chess_move(MOVES.BISHOP)
+        self.assertEqual(board.player.movement_mode, MOVES.BISHOP)
+
+    def test_allow_chess_move_castle(self):
+        board = GameBoard.new_game([{'actions': []}])
+        board.board_locations = self.generate_locations()
+        board.allow_chess_move(MOVES.CASTLE)
+        self.assertEqual(board.player.movement_mode, MOVES.CASTLE)
+
+
 
 class TestLocationCard(TestCase):
     def test_generate_bitwise_operand(self):
index d45c09eadcdad3957862611d5f337b41919c4f56..a7173cbc794ce6b7571dfb3962532c4b2e4e6212 100644 (file)
@@ -1,6 +1,6 @@
 from unittest import TestCase
 
-from naja.constants import BITS
+from naja.constants import BITS, MOVES
 from naja.player import PlayerBits, Player
 
 
@@ -136,11 +136,11 @@ class TestPlayer(TestCase):
     def test_legal_moves_bishop(self):
         player = Player(0x0f, (1, 3), MOVES.BISHOP)
         self.assertEqual(player.legal_moves(), [(0, 2), (0, 4), (1, 3), (2, 2),
-        (2, 4), (3, 1), (3, 4), (4, 0)])
+        (2, 4), (3, 1), (4, 0)])
 
     def test_legal_moves_knight(self):
         player = Player(0x0f, (1, 3), MOVES.KNIGHT)
-        self.assertEqual(player.legal_moves(), [(0, 1), (2, 1), (3, 2), (3, 4)])
+        self.assertEqual(player.legal_moves(), [(0, 1), (1, 3), (2, 1), (3, 2), (3, 4)])
 
     def test_set_position(self):
         player = Player(0x0f, (3, 3), MOVES.BISHOP)