JUnit Tests für Domain und Fassade
parent
8da0e90a5c
commit
c474b457b6
|
@ -197,7 +197,7 @@ public class GameBoard extends JPanel {
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleCellState(HitoriCell cell, int row, int col) {
|
public void toggleCellState(HitoriCell cell, int row, int col) {
|
||||||
if (cell == null) {
|
if (cell == null) {
|
||||||
System.err.println("Ungültige Zelle! Der Zustand kann nicht geändert werden.");
|
System.err.println("Ungültige Zelle! Der Zustand kann nicht geändert werden.");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package Domain;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Domain.Action;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class ActionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConstructorAndGetters() {
|
||||||
|
Action action = new Action(2, 3, "WHITE", "BLACK");
|
||||||
|
assertEquals(2, action.getRow());
|
||||||
|
assertEquals(3, action.getCol());
|
||||||
|
assertEquals("WHITE", action.getOldState());
|
||||||
|
assertEquals("BLACK", action.getNewState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEqualsAndHashCode() {
|
||||||
|
Action action1 = new Action(1, 2, "GRAY", "WHITE");
|
||||||
|
Action action2 = new Action(1, 2, "GRAY", "WHITE");
|
||||||
|
assertEquals(action1, action2);
|
||||||
|
assertEquals(action1.hashCode(), action2.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToString() {
|
||||||
|
Action action = new Action(4, 5, "GRAY", "BLACK");
|
||||||
|
assertEquals("4,5,GRAY,BLACK", action.toString());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package Domain;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriCell;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class HitoriBoardTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBoardInitialization() {
|
||||||
|
int[][] numbers = {{1, 2}, {3, 4}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2"), "TestBoard");
|
||||||
|
assertEquals(2, board.getSize());
|
||||||
|
assertEquals("TestBoard", board.getBoardName());
|
||||||
|
assertEquals(1, board.getCell(0, 0).getNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResetBoard() {
|
||||||
|
int[][] numbers = {{5, 6}, {7, 8}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2"), "ResetTest");
|
||||||
|
board.resetBoard();
|
||||||
|
assertEquals(HitoriCell.CellState.GRAY, board.getCell(0, 0).getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetAndGetNumbers() {
|
||||||
|
int[][] initialNumbers = {{9, 10}, {11, 12}};
|
||||||
|
HitoriBoard board = new HitoriBoard(initialNumbers, Arrays.asList(), "SetNumbersTest");
|
||||||
|
int[][] newNumbers = {{1, 2}, {3, 4}};
|
||||||
|
board.setNumbers(newNumbers);
|
||||||
|
assertArrayEquals(newNumbers, board.getNumbers());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package Domain;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriCell;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class HitoriCellTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCellInitialization() {
|
||||||
|
HitoriCell cell = new HitoriCell(7);
|
||||||
|
assertEquals(7, cell.getNumber());
|
||||||
|
assertEquals(HitoriCell.CellState.GRAY, cell.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetState() {
|
||||||
|
HitoriCell cell = new HitoriCell(8);
|
||||||
|
cell.setState(HitoriCell.CellState.BLACK);
|
||||||
|
assertEquals(HitoriCell.CellState.BLACK, cell.getState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
package Domain;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriValidator;
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriCell;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class HitoriValidatorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateBoardValidSolution() {
|
||||||
|
// Spielfeld-Setup
|
||||||
|
int[][] numbers = {{1, 2, 3}, {4, 1, 6}, {7, 8, 1}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2", "3,3"), "ValidSolutionTest");
|
||||||
|
|
||||||
|
// Lösung manuell setzen (alle Zellen aus der Lösungsliste auf BLACK setzen)
|
||||||
|
board.getCell(0, 0).setState(HitoriCell.CellState.BLACK); // Koordinaten 1,1
|
||||||
|
board.getCell(1, 1).setState(HitoriCell.CellState.BLACK); // Koordinaten 2,2
|
||||||
|
board.getCell(2, 2).setState(HitoriCell.CellState.BLACK); // Koordinaten 3,3
|
||||||
|
|
||||||
|
// Alle anderen Zellen auf WHITE setzen
|
||||||
|
for (int i = 0; i < board.getSize(); i++) {
|
||||||
|
for (int j = 0; j < board.getSize(); j++) {
|
||||||
|
if (!Arrays.asList("1,1", "2,2", "3,3").contains((i + 1) + "," + (j + 1))) {
|
||||||
|
board.getCell(i, j).setState(HitoriCell.CellState.WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validator initialisieren und prüfen
|
||||||
|
HitoriValidator validator = new HitoriValidator(board);
|
||||||
|
assertTrue(validator.validateBoard(Arrays.asList("1,1", "2,2", "3,3")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateBoardInvalidSolution() {
|
||||||
|
// Spielfeld-Setup
|
||||||
|
int[][] numbers = {{1, 2, 3}, {4, 1, 6}, {7, 8, 1}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2", "3,3"), "InvalidSolutionTest");
|
||||||
|
|
||||||
|
// Ungültige Lösung setzen (eine Zelle aus der Lösungsliste bleibt nicht BLACK)
|
||||||
|
board.getCell(0, 0).setState(HitoriCell.CellState.BLACK); // Koordinaten 1,1
|
||||||
|
board.getCell(1, 1).setState(HitoriCell.CellState.WHITE); // Koordinaten 2,2 (falsch)
|
||||||
|
board.getCell(2, 2).setState(HitoriCell.CellState.BLACK); // Koordinaten 3,3
|
||||||
|
|
||||||
|
// Alle anderen Zellen auf WHITE setzen
|
||||||
|
for (int i = 0; i < board.getSize(); i++) {
|
||||||
|
for (int j = 0; j < board.getSize(); j++) {
|
||||||
|
if (!Arrays.asList("1,1", "2,2", "3,3").contains((i + 1) + "," + (j + 1))) {
|
||||||
|
board.getCell(i, j).setState(HitoriCell.CellState.WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validator initialisieren und prüfen
|
||||||
|
HitoriValidator validator = new HitoriValidator(board);
|
||||||
|
assertFalse(validator.validateBoard(Arrays.asList("1,1", "2,2", "3,3")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateBoardExtraBlackCells() {
|
||||||
|
// Spielfeld-Setup
|
||||||
|
int[][] numbers = {{1, 2, 3}, {4, 1, 6}, {7, 8, 1}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2", "3,3"), "ExtraBlackCellsTest");
|
||||||
|
|
||||||
|
// Lösung setzen
|
||||||
|
board.getCell(0, 0).setState(HitoriCell.CellState.BLACK); // Koordinaten 1,1
|
||||||
|
board.getCell(1, 1).setState(HitoriCell.CellState.BLACK); // Koordinaten 2,2
|
||||||
|
board.getCell(2, 2).setState(HitoriCell.CellState.BLACK); // Koordinaten 3,3
|
||||||
|
|
||||||
|
// Zusätzliche schwarze Zelle setzen (ungültig)
|
||||||
|
board.getCell(0, 1).setState(HitoriCell.CellState.BLACK); // Koordinaten 1,2 (nicht Teil der Lösung)
|
||||||
|
|
||||||
|
// Alle anderen Zellen auf WHITE setzen
|
||||||
|
for (int i = 0; i < board.getSize(); i++) {
|
||||||
|
for (int j = 0; j < board.getSize(); j++) {
|
||||||
|
if (!Arrays.asList("1,1", "2,2", "3,3", "1,2").contains((i + 1) + "," + (j + 1))) {
|
||||||
|
board.getCell(i, j).setState(HitoriCell.CellState.WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validator initialisieren und prüfen
|
||||||
|
HitoriValidator validator = new HitoriValidator(board);
|
||||||
|
assertFalse(validator.validateBoard(Arrays.asList("1,1", "2,2", "3,3")));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package Domain;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Domain.StateFileManager;
|
||||||
|
import PR2.HitoriSpiel.Domain.Action;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import java.util.Stack;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class StateFileManagerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveAndLoadState() {
|
||||||
|
Stack<Action> undoStack = new Stack<>();
|
||||||
|
Stack<Action> redoStack = new Stack<>();
|
||||||
|
|
||||||
|
undoStack.push(new Action(1, 1, "GRAY", "BLACK"));
|
||||||
|
redoStack.push(new Action(2, 2, "WHITE", "GRAY"));
|
||||||
|
|
||||||
|
StateFileManager.saveState(undoStack, redoStack);
|
||||||
|
|
||||||
|
Stack<Action> loadedUndo = new Stack<>();
|
||||||
|
Stack<Action> loadedRedo = new Stack<>();
|
||||||
|
StateFileManager.loadState(loadedUndo, loadedRedo);
|
||||||
|
|
||||||
|
assertEquals(undoStack, loadedUndo);
|
||||||
|
assertEquals(redoStack, loadedRedo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
package Fassade;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriCell;
|
||||||
|
import PR2.HitoriSpiel.Fassade.GameBoard;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class GameBoardTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGameBoardInitialization() {
|
||||||
|
int[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2", "3,3"), "TestBoard");
|
||||||
|
GameBoard gameBoard = new GameBoard(board);
|
||||||
|
|
||||||
|
assertNotNull(gameBoard, "GameBoard sollte erfolgreich initialisiert werden.");
|
||||||
|
assertNotNull(gameBoard.validateCurrentBoard(), "Das Spielfeld sollte validierbar sein.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResetBoard() {
|
||||||
|
int[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2", "3,3"), "TestBoard");
|
||||||
|
GameBoard gameBoard = new GameBoard(board);
|
||||||
|
|
||||||
|
// Setze einige Zellen auf unterschiedliche Zustände
|
||||||
|
board.getCell(0, 0).setState(HitoriCell.CellState.BLACK);
|
||||||
|
board.getCell(1, 1).setState(HitoriCell.CellState.WHITE);
|
||||||
|
|
||||||
|
// Führe das Zurücksetzen durch
|
||||||
|
gameBoard.resetBoard();
|
||||||
|
|
||||||
|
// Verifiziere, dass alle Zellen zurückgesetzt wurden
|
||||||
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
|
for (int j = 0; j < numbers[i].length; j++) {
|
||||||
|
assertEquals(HitoriCell.CellState.GRAY, board.getCell(i, j).getState(),
|
||||||
|
"Alle Zellen sollten nach dem Zurücksetzen grau sein.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateCurrentBoard() {
|
||||||
|
int[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2", "3,3"), "TestBoard");
|
||||||
|
GameBoard gameBoard = new GameBoard(board);
|
||||||
|
|
||||||
|
// Setze Zellen auf die Lösung
|
||||||
|
board.getCell(0, 0).setState(HitoriCell.CellState.BLACK);
|
||||||
|
board.getCell(1, 1).setState(HitoriCell.CellState.BLACK);
|
||||||
|
board.getCell(2, 2).setState(HitoriCell.CellState.BLACK);
|
||||||
|
|
||||||
|
// Alle anderen Zellen auf weiß setzen
|
||||||
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
|
for (int j = 0; j < numbers[i].length; j++) {
|
||||||
|
if (!Arrays.asList("1,1", "2,2", "3,3").contains((i + 1) + "," + (j + 1))) {
|
||||||
|
board.getCell(i, j).setState(HitoriCell.CellState.WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(gameBoard.validateCurrentBoard(), "Das Board sollte als gültig erkannt werden.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToggleCellState() {
|
||||||
|
int[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
|
||||||
|
HitoriBoard board = new HitoriBoard(numbers, Arrays.asList("1,1", "2,2", "3,3"), "TestBoard");
|
||||||
|
GameBoard gameBoard = new GameBoard(board);
|
||||||
|
|
||||||
|
HitoriCell cell = board.getCell(0, 0);
|
||||||
|
|
||||||
|
// Initialer Zustand: GRAY
|
||||||
|
assertEquals(HitoriCell.CellState.GRAY, cell.getState(), "Die Zelle sollte initial grau sein.");
|
||||||
|
|
||||||
|
// Zustand wechseln: BLACK
|
||||||
|
gameBoard.toggleCellState(cell, 0, 0);
|
||||||
|
assertEquals(HitoriCell.CellState.BLACK, cell.getState(), "Die Zelle sollte schwarz sein.");
|
||||||
|
|
||||||
|
// Zustand wechseln: WHITE
|
||||||
|
gameBoard.toggleCellState(cell, 0, 0);
|
||||||
|
assertEquals(HitoriCell.CellState.WHITE, cell.getState(), "Die Zelle sollte weiß sein.");
|
||||||
|
|
||||||
|
// Zustand wechseln: GRAY
|
||||||
|
gameBoard.toggleCellState(cell, 0, 0);
|
||||||
|
assertEquals(HitoriCell.CellState.GRAY, cell.getState(), "Die Zelle sollte wieder grau sein.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package Fassade;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Fassade.HighscoreManager;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class HighscoreManagerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddHighscore() {
|
||||||
|
HighscoreManager manager = new HighscoreManager();
|
||||||
|
manager.addHighscore("Alice", 120, "TestBoard", 0);
|
||||||
|
List<HighscoreManager.Highscore> highscores = manager.getHighscoresForBoard("TestBoard");
|
||||||
|
|
||||||
|
assertEquals(1, highscores.size());
|
||||||
|
assertEquals("Alice", highscores.get(0).getPlayerName());
|
||||||
|
assertEquals(120, highscores.get(0).getTime());
|
||||||
|
assertEquals("TestBoard", highscores.get(0).getBoardName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsNewHighscore() {
|
||||||
|
HighscoreManager manager = new HighscoreManager();
|
||||||
|
manager.addHighscore("Bob", 150, "TestBoard", 0);
|
||||||
|
|
||||||
|
assertTrue(manager.isNewHighscore(140, "TestBoard"));
|
||||||
|
assertFalse(manager.isNewHighscore(160, "TestBoard"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClearHighscores() {
|
||||||
|
HighscoreManager manager = new HighscoreManager();
|
||||||
|
manager.addHighscore("Alice", 100, "TestBoard", 0);
|
||||||
|
|
||||||
|
manager.clearHighscores();
|
||||||
|
List<HighscoreManager.Highscore> highscores = manager.getHighscores();
|
||||||
|
|
||||||
|
assertTrue(highscores.isEmpty(), "Alle Highscores sollten gelöscht sein.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
package Fassade;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Fassade.HitoriSolutionLoader;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class HitoriSolutionLoaderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadSolutionValidFile() throws IOException {
|
||||||
|
// Simuliere eine valide Lösung im InputStream
|
||||||
|
String solutionContent = """
|
||||||
|
//Lösung
|
||||||
|
1,1
|
||||||
|
2,2
|
||||||
|
3,3
|
||||||
|
""";
|
||||||
|
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(solutionContent.getBytes());
|
||||||
|
|
||||||
|
// Mock den Aufruf von getResourceAsStream
|
||||||
|
List<String> solution = loadSolutionFromStream(inputStream);
|
||||||
|
assertNotNull(solution, "Die Lösungsliste sollte nicht null sein.");
|
||||||
|
assertFalse(solution.isEmpty(), "Die Lösungsliste sollte nicht leer sein.");
|
||||||
|
assertEquals("1,1", solution.get(0), "Die erste Koordinate sollte korrekt geladen werden.");
|
||||||
|
assertEquals("3,3", solution.get(2), "Die letzte Koordinate sollte korrekt geladen werden.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadSolutionNoSolutionSection() throws IOException {
|
||||||
|
// Simuliere eine Datei ohne "//Lösung"
|
||||||
|
String solutionContent = """
|
||||||
|
1,1
|
||||||
|
2,2
|
||||||
|
3,3
|
||||||
|
""";
|
||||||
|
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(solutionContent.getBytes());
|
||||||
|
|
||||||
|
// Mock den Aufruf von getResourceAsStream
|
||||||
|
List<String> solution = loadSolutionFromStream(inputStream);
|
||||||
|
assertNotNull(solution, "Die Lösungsliste sollte nicht null sein.");
|
||||||
|
assertTrue(solution.isEmpty(), "Die Lösungsliste sollte leer sein, wenn kein Lösungsteil gefunden wird.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadSolutionWithEmptyLines() throws IOException {
|
||||||
|
// Simuliere eine Datei mit leeren Zeilen
|
||||||
|
String solutionContent = """
|
||||||
|
//Lösung
|
||||||
|
|
||||||
|
1,1
|
||||||
|
|
||||||
|
2,2
|
||||||
|
3,3
|
||||||
|
""";
|
||||||
|
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(solutionContent.getBytes());
|
||||||
|
|
||||||
|
// Mock den Aufruf von getResourceAsStream
|
||||||
|
List<String> solution = loadSolutionFromStream(inputStream);
|
||||||
|
assertNotNull(solution, "Die Lösungsliste sollte nicht null sein.");
|
||||||
|
assertFalse(solution.isEmpty(), "Die Lösungsliste sollte nicht leer sein.");
|
||||||
|
assertEquals(3, solution.size(), "Die Lösungsliste sollte nur 3 gültige Einträge enthalten.");
|
||||||
|
assertEquals("1,1", solution.get(0), "Die erste Koordinate sollte korrekt geladen werden.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Hilfsmethode: Simuliert die Verarbeitung des InputStreams
|
||||||
|
private List<String> loadSolutionFromStream(InputStream inputStream) throws IOException {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
|
List<String> solutionCoordinates = new ArrayList<>();
|
||||||
|
boolean solutionSectionFound = false;
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
line = line.trim();
|
||||||
|
|
||||||
|
if (line.startsWith("//Lösung")) {
|
||||||
|
solutionSectionFound = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (solutionSectionFound) {
|
||||||
|
if (!line.isEmpty()) {
|
||||||
|
solutionCoordinates.add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!solutionSectionFound) {
|
||||||
|
System.err.println("Warnung: Lösungsteil wurde in der Datei nicht gefunden.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return solutionCoordinates;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package Fassade;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Fassade.Setup;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class SetupTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateButton() {
|
||||||
|
JButton button = Setup.createButton("TestButton", 100, 50);
|
||||||
|
|
||||||
|
assertNotNull(button);
|
||||||
|
assertEquals("TestButton", button.getText());
|
||||||
|
assertEquals(new Dimension(100, 50), button.getPreferredSize());
|
||||||
|
assertEquals(Setup.BUTTON_COLOR, button.getBackground());
|
||||||
|
assertEquals(Setup.BUTTON_TEXT_COLOR, button.getForeground());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateGameBoardButton() {
|
||||||
|
JButton button = Setup.createGameBoardButton("GameButton", 150, 60);
|
||||||
|
|
||||||
|
assertNotNull(button);
|
||||||
|
assertEquals("GameButton", button.getText());
|
||||||
|
assertEquals(new Dimension(150, 60), button.getPreferredSize());
|
||||||
|
assertEquals(Setup.GAME_BUTTON_COLOR, button.getBackground());
|
||||||
|
assertEquals(Setup.GAME_BUTTON_TEXT_COLOR, button.getForeground());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package Fassade;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Fassade.StateManager;
|
||||||
|
import PR2.HitoriSpiel.Domain.Action;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class StateManagerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveActionAndUndo() {
|
||||||
|
StateManager stateManager = new StateManager();
|
||||||
|
stateManager.saveAction(0, 0, "GRAY", "BLACK");
|
||||||
|
|
||||||
|
Action undoAction = stateManager.undo();
|
||||||
|
assertNotNull(undoAction);
|
||||||
|
assertEquals(0, undoAction.getRow());
|
||||||
|
assertEquals(0, undoAction.getCol());
|
||||||
|
assertEquals("GRAY", undoAction.getOldState());
|
||||||
|
assertEquals("BLACK", undoAction.getNewState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRedo() {
|
||||||
|
StateManager stateManager = new StateManager();
|
||||||
|
stateManager.saveAction(1, 1, "WHITE", "BLACK");
|
||||||
|
|
||||||
|
stateManager.undo();
|
||||||
|
Action redoAction = stateManager.redo();
|
||||||
|
assertNotNull(redoAction);
|
||||||
|
assertEquals(1, redoAction.getRow());
|
||||||
|
assertEquals(1, redoAction.getCol());
|
||||||
|
assertEquals("WHITE", redoAction.getOldState());
|
||||||
|
assertEquals("BLACK", redoAction.getNewState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadStateFromFile() {
|
||||||
|
StateManager stateManager = new StateManager();
|
||||||
|
stateManager.saveAction(0, 0, "GRAY", "BLACK");
|
||||||
|
stateManager.saveAction(1, 1, "WHITE", "BLACK");
|
||||||
|
|
||||||
|
stateManager.loadStateFromFile();
|
||||||
|
|
||||||
|
assertNotNull(stateManager.undo(), "Der Undo-Stack sollte geladen werden.");
|
||||||
|
assertNotNull(stateManager.redo(), "Der Redo-Stack sollte geladen werden.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue