Compare commits

...

2 commits

Author SHA1 Message Date
Imbus
ffd1d4bd51 Fixing broken test case 2023-12-11 16:06:50 +01:00
Imbus
5bf0c92d10 Error checking inputs and reverting if illegal 2023-12-11 15:53:22 +01:00
2 changed files with 11 additions and 1 deletions

View file

@ -127,6 +127,15 @@ public class SudokuController {
// Update the model and view
model.set(row, col, value);
// Warn if the board is not solvable (e.g. if the user has made a mistake)
// This is very messy, error prone and computationally expensive
if(!model.isSolvable()) {
model.set(row, col, 0);
view.showErrorMessage("Illegal move. The board is not solvable.");
}
// Sync the view with the model
view.updateView(model.getBoard());
}
}

View file

@ -34,7 +34,8 @@ class SolverTest {
assertTrue(solver.isLegal(0, 0, 1));
solver.set(0, 0, 1);
IntStream.range(0, 9).forEach(i -> {
// Start from one, since setting the same value is legal
IntStream.range(1, 9).forEach(i -> {
assertFalse(solver.isLegal(0, i, 1));
assertFalse(solver.isLegal(i, 0, 1));
});