Compare commits

...

3 commits

Author SHA1 Message Date
Imbus
6ae83248ef Merge branch 'dogge' 2023-12-12 23:11:20 +01:00
Imbus
536f4e1b7d Merge branch 'dogge' 2023-12-12 23:09:56 +01:00
Imbus
7eab9da318 Making sure application is up to spec 2023-12-12 23:08:08 +01:00
2 changed files with 23 additions and 6 deletions

View file

@ -20,10 +20,18 @@ public class Solver implements SudokuSolver {
this.board = board;
}
/** {@inheritDoc} */
/**
* {@inheritDoc}
* <p>
* Note that this returns a copy of the board, not the actual board
*/
@Override
public int[][] getBoard() {
return board;
int[][] copy = new int[9][9];
for (int row = 0; row < 9; row++) {
System.arraycopy(board[row], 0, copy[row], 0, 9);
}
return copy;
}
/** Resets the board to all zeros */
@ -34,7 +42,6 @@ public class Solver implements SudokuSolver {
row[i] = 0;
}
}
// board = new int[9][9];
}
/* {@inheritDoc} */
@ -120,8 +127,8 @@ public class Solver implements SudokuSolver {
}
}
/**
* {@inheritDoc}
/**
* {@inheritDoc}
* <p>
* This is <b>not</b> checked for validity
*/

View file

@ -17,8 +17,12 @@ class SolverTest {
Solver solver = new Solver();
int[][] board = new int[9][9];
solver.setBoard(board);
assertEquals(board, solver.getBoard());
for (int row = 0; row < 9; row++) {
assertArrayEquals(board[row], solver.getBoard()[row]);
}
}
@Test
void randomizeBoardTest() {
@ -28,6 +32,12 @@ class SolverTest {
assertNotEquals(board, solver.getBoard());
}
@Test
void emptyTest() {
Solver solver = new Solver();
assertTrue(solver.solve());
}
@Test
void legalTest() {
Solver solver = new Solver();