Skip to content

Commit

Permalink
Added a test that pawns cannot move through obstructions
Browse files Browse the repository at this point in the history
  • Loading branch information
scl-softwire authored and hugh-emerson committed May 12, 2022
1 parent e17c13d commit ea0387b
Showing 1 changed file with 115 additions and 1 deletion.
116 changes: 115 additions & 1 deletion tests/test_pieces.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,118 @@ def test_black_pawn_cannot_move_down_two_squares_if_already_moved():
moves = pawn.get_available_moves(board)

# Assert
assert Square.at(3, 4) not in moves
assert Square.at(3, 4) not in moves

@staticmethod
def test_white_pawn_cannot_move_if_piece_in_front():

# Arrange
board = Board.empty()
pawn = Pawn(Player.WHITE)
pawn_square = Square.at(4, 4)
board.set_piece(pawn_square, pawn)

obstructing_square = Square.at(5, 4)
obstruction = Pawn(Player.BLACK)
board.set_piece(obstructing_square, obstruction)

# Act
moves = pawn.get_available_moves(board)

# Assert
assert len(moves) == 0

@staticmethod
def test_black_pawn_cannot_move_if_piece_in_front():

# Arrange
board = Board.empty()
pawn = Pawn(Player.BLACK)
pawn_square = Square.at(4, 4)
board.set_piece(pawn_square, pawn)

obstructing_square = Square.at(3, 4)
obstruction = Pawn(Player.WHITE)
board.set_piece(obstructing_square, obstruction)

# Act
moves = pawn.get_available_moves(board)

# Assert
assert len(moves) == 0

@staticmethod
def test_white_pawn_cannot_move_two_squares_if_piece_two_in_front():

# Arrange
board = Board.empty()
pawn = Pawn(Player.WHITE)
pawn_square = Square.at(1, 4)
board.set_piece(pawn_square, pawn)

obstructing_square = Square.at(3, 4)
obstruction = Pawn(Player.BLACK)
board.set_piece(obstructing_square, obstruction)

# Act
moves = pawn.get_available_moves(board)

# Assert
assert obstructing_square not in moves

@staticmethod
def test_black_pawn_cannot_move_two_squares_if_piece_two_in_front():

# Arrange
board = Board.empty()
pawn = Pawn(Player.BLACK)
pawn_square = Square.at(6, 4)
board.set_piece(pawn_square, pawn)

obstructing_square = Square.at(4, 4)
obstruction = Pawn(Player.WHITE)
board.set_piece(obstructing_square, obstruction)

# Act
moves = pawn.get_available_moves(board)

# Assert
assert obstructing_square not in moves

@staticmethod
def test_white_pawn_cannot_move_two_squares_if_piece_one_in_front():

# Arrange
board = Board.empty()
pawn = Pawn(Player.WHITE)
pawn_square = Square.at(1, 4)
board.set_piece(pawn_square, pawn)

obstructing_square = Square.at(2, 4)
obstruction = Pawn(Player.BLACK)
board.set_piece(obstructing_square, obstruction)

# Act
moves = pawn.get_available_moves(board)

# Assert
assert Square.at(3, 4) not in moves

@staticmethod
def test_black_pawn_cannot_move_two_squares_if_piece_one_in_front():

# Arrange
board = Board.empty()
pawn = Pawn(Player.BLACK)
pawn_square = Square.at(6, 4)
board.set_piece(pawn_square, pawn)

obstructing_square = Square.at(5, 4)
obstruction = Pawn(Player.WHITE)
board.set_piece(obstructing_square, obstruction)

# Act
moves = pawn.get_available_moves(board)

# Assert
assert Square.at(4, 4) not in moves

0 comments on commit ea0387b

Please sign in to comment.