131 lines
3.0 KiB
Java
131 lines
3.0 KiB
Java
import domain.HitoriGameMoves;
|
|
|
|
import org.junit.jupiter.api.*;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class HitoriGameMovesTest {
|
|
private HitoriGameMoves game;
|
|
private static final int[][] TEST_BOARD = {
|
|
{1, 2, 1, 3},
|
|
{3, 1, 2, 1},
|
|
{2, 3, 3, 2},
|
|
{1, 2, 1, 3}
|
|
};
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
game = new HitoriGameMoves(TEST_BOARD);
|
|
}
|
|
|
|
@Test
|
|
void testMarkCellAsBlack() {
|
|
// Test valid black marking
|
|
game.markCellAsBlack(0, 1);
|
|
assertFalse(game.getBlackCells()[0][2]);
|
|
assertFalse(game.getWhiteCells()[0][2]);
|
|
|
|
// Test invalid black marking (adjacent to existing black cell)
|
|
|
|
|
|
}
|
|
|
|
@Test
|
|
void testMarkCellAsWhite() {
|
|
game.markCellAsWhite(0, 0);
|
|
assertTrue(game.getWhiteCells()[0][0]);
|
|
assertFalse(game.getBlackCells()[0][0]);
|
|
}
|
|
|
|
@Test
|
|
void testUndo() {
|
|
// Make some moves
|
|
game.markCellAsWhite(0, 0);
|
|
game.markCellAsBlack(1, 1);
|
|
|
|
// Undo last move
|
|
assertTrue(game.undo());
|
|
|
|
// Verify the last move was undone
|
|
assertFalse(game.getBlackCells()[1][1]);
|
|
|
|
// Verify previous move remains
|
|
assertTrue(game.getWhiteCells()[0][0]);
|
|
}
|
|
|
|
@Test
|
|
void testRedo() {
|
|
// Make moves and undo
|
|
game.markCellAsWhite(0, 0);
|
|
game.markCellAsBlack(1, 1);
|
|
game.undo();
|
|
|
|
// Redo last move
|
|
assertTrue(game.redo());
|
|
|
|
// Verify move was redone
|
|
assertTrue(game.getBlackCells()[1][1]);
|
|
}
|
|
|
|
@Test
|
|
void testUndoLimit() {
|
|
// Test undo when no moves made
|
|
assertFalse(game.undo());
|
|
}
|
|
|
|
@Test
|
|
void testRedoLimit() {
|
|
// Make and undo a move
|
|
game.markCellAsWhite(0, 0);
|
|
game.undo();
|
|
assertTrue(game.redo());
|
|
|
|
// Try to redo when at latest state
|
|
assertFalse(game.redo());
|
|
}
|
|
|
|
@Test
|
|
void testMoveHistory() {
|
|
// Make several moves
|
|
game.markCellAsWhite(0, 0);
|
|
game.markCellAsBlack(1, 1);
|
|
game.markCellAsWhite(2, 2);
|
|
|
|
// Undo twice
|
|
game.undo();
|
|
game.undo();
|
|
|
|
// Make new move - should clear redo history
|
|
game.markCellAsBlack(2, 1);
|
|
|
|
// Try to redo - should fail
|
|
assertFalse(game.redo());
|
|
}
|
|
|
|
@Test
|
|
void testReset() {
|
|
// Make some moves
|
|
game.markCellAsWhite(0, 0);
|
|
game.markCellAsBlack(1, 1);
|
|
|
|
// Reset game
|
|
game.reset();
|
|
|
|
// Verify all cells are reset
|
|
boolean[][] blackCells = game.getBlackCells();
|
|
boolean[][] whiteCells = game.getWhiteCells();
|
|
|
|
for (int i = 0; i < TEST_BOARD.length; i++) {
|
|
for (int j = 0; j < TEST_BOARD[0].length; j++) {
|
|
assertFalse(blackCells[i][j]);
|
|
assertFalse(whiteCells[i][j]);
|
|
}
|
|
}
|
|
|
|
// Verify undo/redo history is cleared
|
|
assertFalse(game.undo());
|
|
assertFalse(game.redo());
|
|
}
|
|
|
|
|
|
}
|