refactor solvers
All checks were successful
Linux arm64 / Build (push) Successful in 42s

This commit is contained in:
2025-01-30 18:05:18 +01:00
parent 1f92c49f3c
commit a74bf42e59
11 changed files with 299 additions and 249 deletions

View File

@@ -10,7 +10,7 @@ import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import sudoku.io.SudokuSerializer;
import sudoku.solver.Solver;
import sudoku.solver.RandomSolver;
import sudoku.structure.MultiDoku;
import sudoku.structure.SudokuFactory;
@@ -19,7 +19,7 @@ public class SudokuSerializerTest {
void testSerializeWithSize(int blockWidth, int blockHeight) {
var sudoku = SudokuFactory.createBasicEmptyRectangleDoku(blockWidth, blockHeight,
SudokuFactory.DEFAULT_CONSTRAINTS);
Solver.randomSolve(sudoku, new Random());
new RandomSolver().solve(sudoku);
JSONObject data = SudokuSerializer.serializeSudoku(sudoku);
MultiDoku multiDoku = SudokuSerializer.deserializeSudoku(data);
assertTrue(data.toString().equals(SudokuSerializer.serializeSudoku(multiDoku).toString()));
@@ -28,14 +28,15 @@ public class SudokuSerializerTest {
void testSaveWithSize(int blockWidth, int blockHeight) {
MultiDoku doku = SudokuFactory.createBasicEmptyRectangleDoku(blockWidth, blockHeight,
SudokuFactory.DEFAULT_CONSTRAINTS);
Solver.randomSolve(doku, new Random());
new RandomSolver().solve(doku);
String savePath = SudokuSerializer.saveMultiDoku(doku);
MultiDoku otherDoku = null;
try {
otherDoku = SudokuFactory.fromfile(savePath);
assert (otherDoku != null);
assertEquals(SudokuSerializer.serializeSudoku(doku).toString(), SudokuSerializer.serializeSudoku(otherDoku).toString());
assertEquals(SudokuSerializer.serializeSudoku(doku).toString(),
SudokuSerializer.serializeSudoku(otherDoku).toString());
// clean file after test
File fileToDelete = new File(savePath);
fileToDelete.delete();
@@ -47,7 +48,7 @@ public class SudokuSerializerTest {
void testSerializeX(int size) {
var sudoku = SudokuFactory.createBasicXShapedMultidoku(size, SudokuFactory.DEFAULT_CONSTRAINTS);
Solver.randomSolve(sudoku, new Random());
new RandomSolver().solve(sudoku);
JSONObject data = SudokuSerializer.serializeSudoku(sudoku);
MultiDoku multiDoku = SudokuSerializer.deserializeSudoku(data);

View File

@@ -57,7 +57,7 @@ class SolverTest {
assert (dokuResult.isSolved());
Solver.randomSolve(dokuToTest, rand);
new RandomSolver().solve(dokuToTest);
System.out.println("\n****************************\nDoku solved");
SudokuPrinter.printRectangleSudoku(dokuToTest.getSubGrid(0), 3, 3);
@@ -89,13 +89,13 @@ class SolverTest {
5, ns, ns, ns, 3, 1, 0, ns, ns);
sudokuToTest2.setImmutableCellsSymbol(immutableCells2);
boolean isSolved = Solver.randomSolve(dokuToTest2, rand);
boolean isSolved = new RandomSolver().solve(dokuToTest2);
assert (!isSolved);
MultiDoku dokuToTest3 = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
Solver.randomSolve(dokuToTest3, rand);
new RandomSolver().solve(dokuToTest3);
SudokuPrinter.printRectangleSudoku(dokuToTest3.getSubGrid(0), 3, 3);
}