forked from BracketCove/JavaDesktopSudoku
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameGeneratorTest.java
More file actions
47 lines (38 loc) · 1.53 KB
/
Copy pathGameGeneratorTest.java
File metadata and controls
47 lines (38 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import com.wissassblog.sudoku.computationlogic.GameLogic;
import com.wissassblog.sudoku.problemdomain.SudokuGame;
import org.junit.jupiter.api.Test;
public class GameGeneratorTest {
/**
* Generate a new puzzle based on the appropriate rules, with 30 numbers initially completed.
*/
@Test
public void onGenerateNewPuzzle() {
int[][] newPuzzle = GameLogic.getNewGame().getCopyOfGridState();
int numberOfFilledSquares = 0;
//Traverse array
for (int xIndex = 0; xIndex < 9; xIndex++){
for (int yIndex = 0; yIndex < 9; yIndex++ ){
if (newPuzzle[xIndex][yIndex] != 0) numberOfFilledSquares++;
}
}
//Check of invalid set up
assert (!GameLogic.rowsAreInvalid(newPuzzle));
assert (!GameLogic.columnsAreInvalid(newPuzzle));
assert (!GameLogic.squaresAreInvalid(newPuzzle));
assert (numberOfFilledSquares == 81);
}
/**
* After spending several days sorting out how to generate a new valid sudoku puzzle, this test
* will confirm if my algorithm works.
*/
@Test
public void test100NewPuzzles(){
for (int testIndex = 0; testIndex < 100; testIndex++){
int[][] newPuzzle = GameLogic.getNewGame().getCopyOfGridState();
assert (!GameLogic.rowsAreInvalid(newPuzzle));
assert (!GameLogic.columnsAreInvalid(newPuzzle));
assert (!GameLogic.squaresAreInvalid(newPuzzle));
assert (!GameLogic.tilesAreNotFilled(newPuzzle));
}
}
}