forked from BracketCove/JavaDesktopSudoku
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameLogicTest.java
More file actions
163 lines (137 loc) · 4.29 KB
/
Copy pathGameLogicTest.java
File metadata and controls
163 lines (137 loc) · 4.29 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import com.wissassblog.sudoku.computationlogic.GameLogic;
import com.wissassblog.sudoku.computationlogic.SudokuUtilities;
import com.wissassblog.sudoku.constants.GameState;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
public class GameLogicTest {
/**
* Start with the basic logic to validate a valid Sudoku puzzle
*/
@Test
public void onValidateValidPuzzle() {
assert (GameState.COMPLETE ==
GameLogic.checkForCompletion(
TestData.getSolved().getCopyOfGridState()
)
);
}
@Test
public void onValidateActivePuzzle() {
assert (GameState.ACTIVE ==
GameLogic.checkForCompletion(
TestData.getValidStart().getCopyOfGridState()
)
);
}
@Test
public void canCopyArrayValuesCorrectly()
{
int[][] oldArray = TestData.getInvalid().getCopyOfGridState();
int[][] newArray = SudokuUtilities.copyToNewArray(oldArray);
int[][] newSudokuArray = new int[9][9];
SudokuUtilities.copySudokuArrayValues(oldArray,newSudokuArray);
for(int i = 0; i < oldArray.length - 1; i++)
{
Assertions.assertArrayEquals(newArray[i],newSudokuArray[i]);
Assertions.assertArrayEquals(oldArray[i],newSudokuArray[i]);
}
}
/**
* Expected value: True (i.e. squares are indeed not all filled
*/
@Test
public void gameSquaresAreNotFilled() {
assert (GameLogic.tilesAreNotFilled(TestData.getValidStart().getCopyOfGridState()));
}
/**
* Expected value: false
*/
@Test
public void gameSquaresAreFilled() {
assert (!GameLogic.tilesAreNotFilled(TestData.getSolved().getCopyOfGridState()));
}
/**
* Expected value: true
*/
@Test
public void gameSquaresAreInvalid() {
int[][] invalid = TestData.getInvalid().getCopyOfGridState();
boolean isInvalid = GameLogic.squaresAreInvalid(invalid);
assert (isInvalid);
}
/**
* Expected value: false
*/
@Test
public void gameSquaresAreValid() {
int[][] valid = TestData.getSolved()
.getCopyOfGridState();
boolean isInvalid = GameLogic.squaresAreInvalid(
valid
);
assert (!isInvalid);
}
/**
* Expected value: true
*/
@Test
public void gameColumnsAreInvalid() {
int[][] invalid = TestData.getInvalid()
.getCopyOfGridState();
boolean isInvalid = GameLogic.columnsAreInvalid(
invalid
);
assert (isInvalid);
}
/**
* Expected value: false
*/
@Test
public void gameColumnsAreValid() {
int[][] valid = TestData.getSolved().getCopyOfGridState();
boolean isInvalid = GameLogic.columnsAreInvalid(valid);
assert (!isInvalid);
}
/**
* Expected value: true
*/
@Test
public void gameRowsAreInvalid() {
int[][] invalid = TestData.getInvalid().getCopyOfGridState();
boolean isInvalid = GameLogic.rowsAreInvalid(invalid);
assert (isInvalid);
}
/**
* Expected value: false
*/
@Test
public void gameRowsAreValid() {
int[][] valid = TestData.getSolved().getCopyOfGridState();
boolean isInvalid = GameLogic.rowsAreInvalid(valid);
assert (!isInvalid);
}
/**
* Collection does have repeated integer values (this will be either a row or a column)
* Expected value: true
*/
@Test
public void collectionHasRepeats() {
List<Integer> testList = Arrays.asList(0, 0, 0, 1, 1, 0, 0, 0, 0);
boolean hasRepeats = GameLogic.collectionHasRepeats(testList);
assert (hasRepeats);
}
/**
* Expected value: false
*/
@Test
public void collectionHasNoRepeats() {
List<Integer> testListOne = Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0);
List<Integer> testListTwo = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
boolean hasRepeatsOne = GameLogic.collectionHasRepeats(testListOne);
boolean hasRepeatsTwo = GameLogic.collectionHasRepeats(testListTwo);
assert (!hasRepeatsOne);
assert (!hasRepeatsTwo);
}
}