Skip to content

Commit

Permalink
added white en passant test
Browse files Browse the repository at this point in the history
  • Loading branch information
123Chan committed Aug 14, 2023
1 parent e70f1d4 commit 24b7224
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/test/java/usecases/MovePieceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -860,4 +860,73 @@ void pieceMoveCannotPutKingInCheck() {
// Should be still white's turn
assertTrue(game.getTurn());
}

@Test
void enPassantWhite() {
// Initialize empty chessboard
TestHelper.removeAllPieces(game.getCurrentBoard());

int[][] blackPawn = {
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};

int[][] whitePawn = {
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};

int[][] blackTo = {
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};

int[][] whiteTo = {
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
};

// Place the pieces and update the board
game.getCurrentBoard().blackPawn[0] = TestHelper.bitboardRepresentation(blackPawn);
game.getCurrentBoard().whitePawn[0] = TestHelper.bitboardRepresentation(whitePawn);
game.getCurrentBoard().updateLocationVariables();
// Change to black's turn
game.changeTurn();

movePieceClass.movePiece(TestHelper.bitboardRepresentation(blackPawn), TestHelper.bitboardRepresentation(blackTo));
assertTrue(game.getTurn()); // Should be white's turn now
// new black pawn location after moving
assertEquals(TestHelper.bitboardRepresentation(blackTo), mockPresenter.pieceLocations[1][0]);
movePieceClass.movePiece(TestHelper.bitboardRepresentation(whitePawn), TestHelper.bitboardRepresentation(whiteTo));
assertFalse(game.getTurn()); // Should be black's turn now

// white pawn should have moved
assertEquals(TestHelper.bitboardRepresentation(whiteTo), mockPresenter.pieceLocations[0][0]);
// black pawn should be removed for en passant
assertEquals(0, mockPresenter.pieceLocations[1][0]);
}
}

0 comments on commit 24b7224

Please sign in to comment.