Tests für die Spielzüge implementiert
parent
6f15430fed
commit
89a9a3c0a2
|
|
@ -1,4 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
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, 2);
|
||||
assertTrue(game.getBlackCells()[0][2]);
|
||||
assertFalse(game.getWhiteCells()[0][2]);
|
||||
|
||||
// Test invalid black marking (adjacent to existing black cell)
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
game.markCellAsBlack(0, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMistakeCountIncrement() {
|
||||
// Make valid move
|
||||
game.markCellAsBlack(0, 0);
|
||||
assertEquals(0, game.getMistakeCount());
|
||||
|
||||
// Make invalid move
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
game.markCellAsBlack(0, 1);
|
||||
});
|
||||
assertEquals(1, game.getMistakeCount());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue