You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.6 KiB
100 lines
3.6 KiB
package Game.ChessObj;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
class ChessBoardTest {
|
|
|
|
ChessFigure.Type[] startOrder = {
|
|
ChessFigure.Type.CASTLE, ChessFigure.Type.KNIGHT, ChessFigure.Type.BISHOP, ChessFigure.Type.QUEEN, ChessFigure.Type.KING, ChessFigure.Type.BISHOP, ChessFigure.Type.KNIGHT, ChessFigure.Type.CASTLE
|
|
};
|
|
|
|
ChessBoard chessBoard;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
chessBoard = new ChessBoard();
|
|
}
|
|
|
|
@AfterEach
|
|
void tearDown() {
|
|
}
|
|
|
|
@Test
|
|
void initBoard() {
|
|
ChessFigure[][] board = chessBoard.getBoard();
|
|
for (int x = 0; x < board[0].length; x++) {
|
|
for (int y = 0; y < board.length; y++) {
|
|
//test pawns
|
|
if (y == 1) {
|
|
assertEquals(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.BLACK), board[y][x]);
|
|
continue;
|
|
}
|
|
if (y == 6) {
|
|
assertEquals(new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE), board[y][x]);
|
|
continue;
|
|
}
|
|
|
|
if (y == 0) {
|
|
assertEquals(new ChessFigure(startOrder[x], ChessFigure.Team.BLACK), board[y][x]);
|
|
continue;
|
|
}
|
|
if (y == 7) {
|
|
assertEquals(new ChessFigure(startOrder[x], ChessFigure.Team.WHITE), board[y][x]);
|
|
continue;
|
|
}
|
|
//rest should be empty(null)
|
|
assertNull(board[y][x]);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test
|
|
void getCellSymbols() {
|
|
String[][] expectedArray = {
|
|
{"|T|", "|Z|", "|I|", "|Q|", "|K|", "|I|", "|Z|", "|T|"},
|
|
{"|o|", "|o|", "|o|", "|o|", "|o|", "|o|", "|o|", "|o|"},
|
|
{" ", " ", " ", " ", " ", " ", " ", " "},
|
|
{" ", " ", " ", " ", " ", " ", " ", " "},
|
|
{" ", " ", " ", " ", " ", " ", " ", " "},
|
|
{" ", " ", " ", " ", " ", " ", " ", " "},
|
|
{" o ", " o ", " o ", " o ", " o ", " o ", " o ", " o "},
|
|
{" T ", " Z ", " I ", " Q ", " K ", " I ", " Z ", " T "}
|
|
};
|
|
assertArrayEquals(expectedArray, chessBoard.getCellSymbols());
|
|
}
|
|
|
|
@Test
|
|
void isCellInBoard() {
|
|
assertTrue(chessBoard.isCellInBoard(0, 0));
|
|
assertTrue(chessBoard.isCellInBoard(7, 7));
|
|
assertTrue(chessBoard.isCellInBoard(2, 1));
|
|
assertTrue(chessBoard.isCellInBoard(5, 7));
|
|
assertFalse(chessBoard.isCellInBoard(-1, 0));
|
|
assertFalse(chessBoard.isCellInBoard(4, 8));
|
|
assertFalse(chessBoard.isCellInBoard(10, 20));
|
|
}
|
|
|
|
@Test
|
|
void validateCleanPath() {
|
|
ChessFigure[][] tempBoard = chessBoard.getBoard();
|
|
|
|
tempBoard[3][0] = mock(ChessFigure.class);
|
|
tempBoard[3][5] = mock(ChessFigure.class);
|
|
chessBoard.setChessBoard(tempBoard);
|
|
|
|
assertFalse(chessBoard.validateCleanPath(-2, 0, 1, 4));
|
|
assertTrue(chessBoard.validateCleanPath(0, 3, 5, 3));
|
|
assertFalse(chessBoard.validateCleanPath(0, 3, 6, 3));
|
|
assertFalse(chessBoard.validateCleanPath(0, 3, 7, 3));
|
|
assertFalse(chessBoard.validateCleanPath(0, 3, 5, 5));
|
|
assertFalse(chessBoard.validateCleanPath(0, 3, 4, 7));
|
|
assertTrue(chessBoard.validateCleanPath(0, 3, 2, 5));
|
|
assertTrue(chessBoard.validateCleanPath(7, 3, 5, 5));
|
|
assertFalse(chessBoard.validateCleanPath(7, 3, 6, 6));
|
|
}
|
|
}
|