From 24b7224e2f19e2850733f8520a0aa5635bd4d07d Mon Sep 17 00:00:00 2001 From: 123Chan Date: Sun, 13 Aug 2023 23:22:45 -0400 Subject: [PATCH] added white en passant test --- src/test/java/usecases/MovePieceTest.java | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/test/java/usecases/MovePieceTest.java b/src/test/java/usecases/MovePieceTest.java index c61c51e..d0c85e5 100644 --- a/src/test/java/usecases/MovePieceTest.java +++ b/src/test/java/usecases/MovePieceTest.java @@ -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]); + } } \ No newline at end of file