コード例 #1
0
    def test_can_move(self):
        """
        test the can_move functionality of a Queen piece.
        :return: None.
        """
        self.piece = Queen()
        second_piece = Queen()
        self.piece.board = Board(4, 4, [self.piece, second_piece])

        self.piece.move(2, 2)
        second_piece.move(1, 1)

        self.assertEqual(self.piece.can_move(0, 2, 1), False)
        self.assertEqual(self.piece.can_move(0, 3, 2), True)
        self.assertEqual(self.piece.can_move(0, 2, 3), True)
コード例 #2
0
class TestQueen(TestPiece):
    """
    Testing a Queen piece functionality with a board set to it.
    """
    def setUp(self):
        """
        setup the test with 1 Queen on a board.
        :return: None.
        """
        self.piece = Queen()
        self.piece.board = Board(4, 4, [self.piece])

    def test_get_moves(self):
        """
        test getting the available moves of a Queen piece.
        :return: None.
        """
        self.setUp()

        moves = self.piece.get_moves()
        moves_should_be = [(1, 0), (2, 0), (3, 0), (0, 1), (0, 2),
                           (0, 3), (1, 1), (2, 2), (3, 3)]
        self.assertEqual(moves, moves_should_be)

        self.piece.move(2, 2)

        moves = self.piece.get_moves()
        moves_should_be = [(0, 2), (1, 2), (3, 2), (2, 0), (2, 1),
                           (2, 3), (3, 1), (1, 3), (0, 0), (1, 1),
                           (3, 3)]

        self.assertEqual(moves, moves_should_be)

    def test_update_column_status(self):
        """
        test updating the column `taken` value of a Queen piece.
        :return: None.
        """
        self.setUp()
        self.piece.move(2, 2)

        for index in xrange(self.piece.board.rows):
            self.assertEqual(self.piece.board[index, 2].taken, True)

        for index in xrange(self.piece.board.rows):
            self.assertEqual(self.piece.board[index, 0].taken, False)

    def test_can_move(self):
        """
        test the can_move functionality of a Queen piece.
        :return: None.
        """
        self.piece = Queen()
        second_piece = Queen()
        self.piece.board = Board(4, 4, [self.piece, second_piece])

        self.piece.move(2, 2)
        second_piece.move(1, 1)

        self.assertEqual(self.piece.can_move(0, 2, 1), False)
        self.assertEqual(self.piece.can_move(0, 3, 2), True)
        self.assertEqual(self.piece.can_move(0, 2, 3), True)