pull/15/head
Nicholas H. 2025-01-07 11:03:17 +01:00
parent 0fa943b045
commit 87f16e0bf1
5 changed files with 24 additions and 88 deletions

View File

@ -24,14 +24,14 @@ class GameBaseTest {
@Test @Test
void testReset() { void testReset() {
// Directly set some cells (since we can't use markCell methods in base class) // Setzt automatisch schwarze Zellen
game.blackCells[0][0] = true; game.blackCells[0][0] = true;
game.whiteCells[1][1] = true; game.whiteCells[1][1] = true;
// Reset game // Reset game
game.reset(); game.reset();
// Verify all cells are reset // Verifiziert, ob alle schwarzen Zellen gelöscht wurden
boolean[][] blackCells = game.getBlackCells(); boolean[][] blackCells = game.getBlackCells();
boolean[][] whiteCells = game.getWhiteCells(); boolean[][] whiteCells = game.getWhiteCells();

View File

@ -32,6 +32,7 @@ class GameUIControllerTest {
@Test @Test
// Checkt ob alle Elemente initialisiert wurden
void testInitialization() { void testInitialization() {
assertNotNull(controller); assertNotNull(controller);
assertNotNull(controller.getBoardPanel()); assertNotNull(controller.getBoardPanel());
@ -65,12 +66,12 @@ class GameUIControllerTest {
@Test @Test
void testResetGame() { void testResetGame() {
// Make some moves first // Feldermarkierungen
controller.handleLeftClick(0, 0); controller.handleLeftClick(0, 0);
controller.handleRightClick(1, 1); controller.handleRightClick(1, 1);
controller.resetGame(); controller.resetGame();
// Verify the board is reset // Verifiziert Boardlöschung
var boardPanel = controller.getBoardPanel(); var boardPanel = controller.getBoardPanel();
assertEquals(9, boardPanel.getChildren().size()); // 3x3 board assertEquals(9, boardPanel.getChildren().size()); // 3x3 board
} }
@ -80,13 +81,13 @@ class GameUIControllerTest {
controller.handleLeftClick(0, 0); controller.handleLeftClick(0, 0);
controller.undo(); controller.undo();
controller.redo(); controller.redo();
// Verify the board state // Verifiziert den Board Status
assertTrue(controller.getBoardPanel().getChildren().size() > 0); assertTrue(controller.getBoardPanel().getChildren().size() > 0);
} }
@Test @Test
void testShowErrors() { void testShowErrors() {
// Create some errors first // Fehler werden kreiert
controller.handleLeftClick(0, 0); controller.handleLeftClick(0, 0);
controller.handleLeftClick(0, 1); controller.handleLeftClick(0, 1);
@ -110,6 +111,7 @@ class GameUIControllerTest {
@Test @Test
// Fehlerspeicherung
void testConvertErrorsToSet() { void testConvertErrorsToSet() {
List<int[]> errors = List.of( List<int[]> errors = List.of(
new int[]{0, 0}, new int[]{0, 0},
@ -126,10 +128,9 @@ class GameUIControllerTest {
assertFalse(controller.isPaused()); assertFalse(controller.isPaused());
} }
// Helper method to simulate winning moves // Hilfsmethode
private void makeWinningMoves() { private void makeWinningMoves() {
// This would need to be implemented according to your winning condition // Win
// For test purposes, we'll just make some moves
controller.handleLeftClick(0, 2); controller.handleLeftClick(0, 2);
controller.handleRightClick(0, 0); controller.handleRightClick(0, 0);
controller.handleRightClick(0, 1); controller.handleRightClick(0, 1);

View File

@ -29,7 +29,7 @@ class HitoriControlPanelTest {
void testUpdateTimerLabel() { void testUpdateTimerLabel() {
controlPanel.updateTimerLabel(42); controlPanel.updateTimerLabel(42);
var timerLabel = findLabelByText(controlPanel, "Time: 42s"); var timerLabel = findLabelByText(controlPanel, "Time: 42s");
assertNotNull(5); assertNotNull(42);
} }
@Test @Test

View File

@ -1,63 +0,0 @@
import domain.HitoriBoardLoader;
import GUI.HitoriDialogManager;
import javafx.stage.Stage;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@ExtendWith(ApplicationExtension.class)
class HitoriDialogManagerTest {
private HitoriDialogManager dialogManager;
private Stage stage;
private HitoriBoardLoader boardLoader;
@Start
private void start(Stage stage) {
this.stage = stage;
}
@BeforeEach
void setUp() {
boardLoader = mock(HitoriBoardLoader.class);
dialogManager = new HitoriDialogManager(stage);
}
@Test
void testShowAlert() {
// Cannot directly test Alert dialogs in headless mode
assertDoesNotThrow(() ->
dialogManager.showAlert("Test", "Test Message")
);
}
@Test
void testConfirmDeleteHighScores() {
// Cannot directly test confirmation dialogs in headless mode
assertDoesNotThrow(() ->
dialogManager.confirmDeleteHighScores()
);
}
@Test
void testConfirmNewGame() {
// Cannot directly test confirmation dialogs in headless mode
assertDoesNotThrow(() ->
dialogManager.confirmNewGame()
);
}
@Test
void testConfirmLoadSavedGame() {
// Cannot directly test confirmation dialogs in headless mode
assertDoesNotThrow(() ->
dialogManager.confirmLoadSavedGame()
);
}
}

View File

@ -19,12 +19,12 @@ class HitoriGameMovesTest {
@Test @Test
void testMarkCellAsBlack() { void testMarkCellAsBlack() {
// Test valid black marking // Testet schwarze Markierung
game.markCellAsBlack(0, 1); game.markCellAsBlack(0, 1);
assertFalse(game.getBlackCells()[0][2]); assertFalse(game.getBlackCells()[0][2]);
assertFalse(game.getWhiteCells()[0][2]); assertFalse(game.getWhiteCells()[0][2]);
// Test invalid black marking (adjacent to existing black cell)
} }
@ -42,50 +42,49 @@ class HitoriGameMovesTest {
game.markCellAsWhite(0, 0); game.markCellAsWhite(0, 0);
game.markCellAsBlack(1, 1); game.markCellAsBlack(1, 1);
// Undo last move // Löscht letzten Schritt
assertTrue(game.undo()); assertTrue(game.undo());
// Verify the last move was undone // Verified das der letzte Schritt gelöscht wurde
assertFalse(game.getBlackCells()[1][1]); assertFalse(game.getBlackCells()[1][1]);
// Verify previous move remains // Verifiziert, dass der vorherige Move gespeichert wurde
assertTrue(game.getWhiteCells()[0][0]); assertTrue(game.getWhiteCells()[0][0]);
} }
@Test @Test
void testRedo() { void testRedo() {
// Make moves and undo // Wiederholt den Test
game.markCellAsWhite(0, 0); game.markCellAsWhite(0, 0);
game.markCellAsBlack(1, 1); game.markCellAsBlack(1, 1);
game.undo(); game.undo();
// Redo last move
assertTrue(game.redo()); assertTrue(game.redo());
// Verify move was redone
assertTrue(game.getBlackCells()[1][1]); assertTrue(game.getBlackCells()[1][1]);
} }
@Test @Test
void testUndoLimit() { void testUndoLimit() {
// Test undo when no moves made // Undo ohne vorherigen Move
assertFalse(game.undo()); assertFalse(game.undo());
} }
@Test @Test
void testRedoLimit() { void testRedoLimit() {
// Make and undo a move // Undo und dann ein Move
game.markCellAsWhite(0, 0); game.markCellAsWhite(0, 0);
game.undo(); game.undo();
assertTrue(game.redo()); assertTrue(game.redo());
// Try to redo when at latest state
assertFalse(game.redo()); assertFalse(game.redo());
} }
@Test @Test
void testMoveHistory() { void testMoveHistory() {
// Make several moves
game.markCellAsWhite(0, 0); game.markCellAsWhite(0, 0);
game.markCellAsBlack(1, 1); game.markCellAsBlack(1, 1);
game.markCellAsWhite(2, 2); game.markCellAsWhite(2, 2);
@ -103,14 +102,13 @@ class HitoriGameMovesTest {
@Test @Test
void testReset() { void testReset() {
// Make some moves
game.markCellAsWhite(0, 0); game.markCellAsWhite(0, 0);
game.markCellAsBlack(1, 1); game.markCellAsBlack(1, 1);
// Reset game // Reset game
game.reset(); game.reset();
// Verify all cells are reset // Verifiziert den Reset
boolean[][] blackCells = game.getBlackCells(); boolean[][] blackCells = game.getBlackCells();
boolean[][] whiteCells = game.getWhiteCells(); boolean[][] whiteCells = game.getWhiteCells();
@ -121,7 +119,7 @@ class HitoriGameMovesTest {
} }
} }
// Verify undo/redo history is cleared // Verified undo/redo history ist closed
assertFalse(game.undo()); assertFalse(game.undo());
assertFalse(game.redo()); assertFalse(game.redo());
} }