Browse Source

Added isCellInBoard for checking positions with test

feature-chess
Nick Stolbov 3 years ago
parent
commit
b7125715f3
  1. 6
      src/main/java/Game/ChessObj/ChessBoard.java
  2. 11
      src/test/java/Game/ChessObj/ChessBoardTest.java

6
src/main/java/Game/ChessObj/ChessBoard.java

@ -76,6 +76,12 @@ public class ChessBoard {
return cellSymbol; return cellSymbol;
} }
public boolean isCellInBoard(int x, int y){
if(x >= 0 && x < board[0].length && y >= 0 && y < board.length)
return true;
return false;
}
public ChessFigure[][] getBoard() { public ChessFigure[][] getBoard() {
return this.board; return this.board;
} }

11
src/test/java/Game/ChessObj/ChessBoardTest.java

@ -66,4 +66,15 @@ class ChessBoardTest {
}; };
assertArrayEquals(expectedArray, chessBoard.getCellSymbols()); 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));
}
} }
Loading…
Cancel
Save