valid tests save and getFromSave sudoku
All checks were successful
Linux arm64 / Build (push) Successful in 42s
All checks were successful
Linux arm64 / Build (push) Successful in 42s
This commit is contained in:
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -17,20 +18,41 @@ public class SudokuSerializerTest {
|
||||
void testSerializeWithSize(int blockWidth, int blockHeight) {
|
||||
var sudoku = SudokuFactory.createBasicEmptyRectangleSudoku(blockWidth, blockHeight);
|
||||
JSONObject data = SudokuSerializer.serializeSudoku(sudoku);
|
||||
SudokuSerializer.saveMultiDoku(sudoku);
|
||||
//MultiDoku multiDoku = SudokuSerializer.deserializeSudoku(data);
|
||||
//assertEquals(data, SudokuSerializer.serializeSudoku(multiDoku));
|
||||
MultiDoku multiDoku = SudokuSerializer.deserializeSudoku(data);
|
||||
assert(data.toString().equals(SudokuSerializer.serializeSudoku(multiDoku).toString()));
|
||||
}
|
||||
|
||||
void testSaveWithSize(int blockWidth, int blockHeight) {
|
||||
MultiDoku doku = SudokuFactory.createBasicEmptyRectangleSudoku(blockWidth, blockHeight);
|
||||
int saveNumber = SudokuSerializer.saveMultiDoku(doku);
|
||||
MultiDoku otherDoku = null;
|
||||
try {
|
||||
otherDoku = SudokuSerializer.getSavedMultiDoku(saveNumber);
|
||||
assert (otherDoku != null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assert false;
|
||||
}
|
||||
assert(doku.equals(otherDoku));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() {
|
||||
int testCount = 5;
|
||||
Random r = new Random();
|
||||
int testCount = 5;
|
||||
for (int i = 0; i < testCount; i++) {
|
||||
int blockWidth = r.nextInt(20) + 1;
|
||||
int blockHeight = r.nextInt(20) + 1;
|
||||
testSerializeWithSize(blockWidth, blockHeight);
|
||||
}
|
||||
for (int i = 0; i < testCount; i++) {
|
||||
int blockWidth = r.nextInt(20) + 1;
|
||||
int blockHeight = r.nextInt(20) + 1;
|
||||
testSaveWithSize(blockWidth, blockHeight);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user