Beispiel #1
0
    def test_clear_square(self):
        b = Board()

        for square, piece in self.data.items():
            # Knock off a piece from the board
            board_piece = b.clear_square(square)
            self.assertEqual(board_piece, piece)

            # Check that the square is now cleared
            square_contents = b.get_piece(square)
            self.assertIsNone(square_contents)
Beispiel #2
0
    def test_add_piece(self):
        b = Board()
        b.clear()

        for square, piece in self.data.items():
            b.add_piece(piece, square)

            # Validate added piece
            expected_result = b.get_piece(square)
            self.assertEqual(piece, expected_result)

            # Validate square for added piece
            expected_result = b.get_square(piece)
            self.assertEqual(square, expected_result)
Beispiel #3
0
    def test_reset(self):
        b = Board()

        # First move some pieces around
        b.move(Square('e2'), Square('e4'))
        b.move(Square('e7'), Square('e5'))

        expected_piece = Piece(
            c.PieceType.pawn,
            c.Color.white,
            order=4,
        )
        self.assertEqual(
            b.get_piece(Square('e4')),
            expected_piece,
        )

        expected_piece = Piece(
            c.PieceType.pawn,
            c.Color.black,
            order=4,
        )
        self.assertEqual(
            b.get_piece(Square('e5')),
            expected_piece,
        )

        # Now let's reset the board
        b.reset()

        for square, piece in b.data.items():
            if b.is_empty(square):
                continue
            expected_piece = self.data[square]

            self.assertEqual(piece, expected_piece)
Beispiel #4
0
 def test_get_piece(self):
     b = Board()
     for square, piece in self.data.items():
         expected_result = b.get_piece(square)
         self.assertEqual(piece, expected_result)