Esempio n. 1
0
    def test_white_capture_right(self, test_board, white_test_pawn):
        assert test_board
        assert white_test_pawn
        assert white_test_pawn.current_space.rank < MAX_RANK

        opposing_pawn = Pawn(-(white_test_pawn.color.value))
        assert opposing_pawn

        # Place the opposing Pawn one space in front of and one space to the right of the test Pawn
        target_file = chr(ord(white_test_pawn.current_space.file) + 1)
        target_rank = white_test_pawn.current_space.rank + 1
        target_space = test_board.get_space(target_file, target_rank)
        opposing_pawn.place(target_space)

        # Capture the opposing Pawn with the test Pawn
        white_test_pawn.capture(target_space)

        # Check that the test Pawn is on the opposing Pawn's previous Space
        assert white_test_pawn.current_space is target_space

        # Check that the opposing Pawn has been removed from the board
        assert opposing_pawn.current_space is None

        # Check that the test Pawn is its Space's current piece
        assert target_space.current_piece is white_test_pawn
Esempio n. 2
0
    def test_place_pawn(self, test_board):
        """
        Explicitly tests the place() method without relying on the
        test_pawn fixture.
        """

        # Check that the intended Space is on the Board with the expected attributes.
        expected_file = random.choice(FILES)
        expected_rank = random.choice(RANKS)
        expected_name = expected_file + str(expected_rank)

        target_space = test_board.get_space(expected_file, expected_rank)

        assert target_space
        assert target_space.file == expected_file
        assert target_space.rank == expected_rank
        assert target_space.name == expected_name

        # Place a Pawn on the intended Space
        expected_color = PieceColor.WHITE
        test_pawn = Pawn(expected_color)

        # Check that the Pawn was created
        assert test_pawn

        test_pawn.place(target_space)

        # Check that the Pawn is on the intended Space
        assert test_pawn.current_space is target_space
        assert test_pawn.moved is False
Esempio n. 3
0
def black_test_pawn(test_board):
    assert test_board

    starting_space = test_board.get_space("e", 7)
    test_pawn = Pawn(PieceColor.BLACK)

    test_pawn.place(starting_space)

    assert test_pawn
    assert test_pawn.current_space is starting_space

    return test_pawn
Esempio n. 4
0
def white_test_pawn(test_board):
    assert test_board

    starting_space = test_board.get_space("e", 2)
    test_pawn = Pawn(PieceColor.WHITE)

    test_pawn.place(starting_space)

    assert test_pawn
    assert test_pawn.current_space is starting_space

    return test_pawn
Esempio n. 5
0
    def move_onto_occupied_square(self, test_board, white_test_pawn):

        assert test_board
        assert white_test_pawn

        # Place a piece directly in front of the test Pawn
        occupying_pawn = Pawn(-(white_test_pawn.color.value))
        occupying_pawn_space = test_board.get_space(
            white_test_pawn.current_space.file,
            white_test_pawn.current_space.rank + 1)
        occupying_pawn.place(occupying_pawn_space)

        # Try to move the test Pawn into the space of the other piece
        target_space = test_board.get_space(
            white_test_pawn.current_space.file,
            white_test_pawn.current_space.rank + 1)
        white_test_pawn.move(test_board, target_space)
Esempio n. 6
0
    def move_over_occupied_square(self, test_board, white_test_pawn):

        assert test_board
        assert white_test_pawn
        assert white_test_pawn.current_space.rank < MAX_RANK - 1

        occupying_pawn = Pawn(-(white_test_pawn.color.value))

        # Place a piece two squares in front of the test Pawn
        occupying_pawn_space = test_board.get_space(
            white_test_pawn.current_space.file,
            white_test_pawn.current_space.rank + 1)
        occupying_pawn.place(occupying_pawn_space)

        # Try to move the test Pawn into the space behind the other piece
        target_space = test_board.get_space(
            white_test_pawn.current_space.file,
            white_test_pawn.current_space.rank + 2)
        white_test_pawn.move(test_board, target_space)
Esempio n. 7
0
    def test_black_capture_left(self, test_board, black_test_pawn):
        assert test_board
        assert black_test_pawn

        opposing_pawn = Pawn(-(black_test_pawn.color.value))
        assert opposing_pawn

        # Place the opposing Pawn one space in front of and one space to the left of the test Pawn
        target_file = chr(ord(black_test_pawn.current_space.file) - 1)
        target_rank = black_test_pawn.current_space.rank - 1
        target_space = test_board.get_space(target_file, target_rank)
        opposing_pawn.place(target_space)

        # Capture the opposing Pawn with the test Pawn
        black_test_pawn.capture(target_space)

        # Check that the test Pawn is on the opposing Pawn's previous Space
        assert black_test_pawn.current_space is target_space

        # Check that the opposing Pawn has been removed from the board
        assert opposing_pawn.current_space is None

        # Check that the test Pawn is its Space's current piece
        assert target_space.current_piece is black_test_pawn