2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
4
5
+ import java .util .stream .Stream ;
5
6
import org .junit .jupiter .params .ParameterizedTest ;
7
+ import org .junit .jupiter .params .provider .Arguments ;
6
8
import org .junit .jupiter .params .provider .CsvSource ;
7
9
import org .junit .jupiter .params .provider .MethodSource ;
8
- import org .junit .jupiter .params .provider .Arguments ;
9
10
10
- import java .util .stream .Stream ;
11
11
12
12
public class SudokuTest {
13
13
@@ -17,30 +17,15 @@ public class SudokuTest {
17
17
*/
18
18
static Stream <Arguments > provideSudokuBoards () {
19
19
return Stream .of (
20
- Arguments .of (new int [][]{
21
- {5 , 3 , 0 , 0 , 7 , 0 , 0 , 0 , 0 },
22
- {6 , 0 , 0 , 1 , 9 , 5 , 0 , 0 , 0 },
23
- {0 , 9 , 8 , 0 , 0 , 0 , 0 , 6 , 0 },
24
- {8 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 3 },
25
- {4 , 0 , 0 , 8 , 0 , 3 , 0 , 0 , 1 },
26
- {7 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 6 },
27
- {0 , 6 , 0 , 0 , 0 , 0 , 2 , 8 , 0 },
28
- {0 , 0 , 0 , 4 , 1 , 9 , 0 , 0 , 5 },
29
- {0 , 0 , 0 , 0 , 8 , 0 , 0 , 7 , 9 }
30
- }, true ),
20
+ Arguments .of (
21
+ new int [][] {{5 , 3 , 0 , 0 , 7 , 0 , 0 , 0 , 0 }, {6 , 0 , 0 , 1 , 9 , 5 , 0 , 0 , 0 }, {0 , 9 , 8 , 0 , 0 , 0 , 0 , 6 , 0 }, {8 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 3 }, {4 , 0 , 0 , 8 , 0 , 3 , 0 , 0 , 1 }, {7 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 6 }, {0 , 6 , 0 , 0 , 0 , 0 , 2 , 8 , 0 }, {0 , 0 , 0 , 4 , 1 , 9 , 0 , 0 , 5 }, {0 , 0 , 0 , 0 , 8 , 0 , 0 , 7 , 9 }}, true ),
31
22
32
- Arguments .of (new int [][]{
33
- {5 , 3 , 0 , 0 , 7 , 0 , 0 , 0 , 0 },
34
- {6 , 0 , 0 , 1 , 9 , 5 , 0 , 0 , 0 },
35
- {0 , 9 , 8 , 0 , 0 , 0 , 0 , 6 , 0 },
36
- {8 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 3 },
37
- {4 , 0 , 0 , 8 , 0 , 3 , 0 , 0 , 1 },
38
- {7 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 6 },
39
- {0 , 6 , 0 , 0 , 0 , 0 , 2 , 8 , 0 },
40
- {0 , 0 , 0 , 4 , 1 , 9 , 0 , 0 , 5 },
23
+ Arguments .of (
24
+ new int [][] {
25
+ {5 , 3 , 0 , 0 , 7 , 0 , 0 , 0 , 0 }, {6 , 0 , 0 , 1 , 9 , 5 , 0 , 0 , 0 }, {0 , 9 , 8 , 0 , 0 , 0 , 0 , 6 , 0 }, {8 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 3 }, {4 , 0 , 0 , 8 , 0 , 3 , 0 , 0 , 1 }, {7 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 6 }, {0 , 6 , 0 , 0 , 0 , 0 , 2 , 8 , 0 }, {0 , 0 , 0 , 4 , 1 , 9 , 0 , 0 , 5 },
41
26
{0 , 0 , 0 , 0 , 8 , 0 , 0 , 7 , 7 } // Invalid board (duplicate '7' in the last row)
42
- }, false )
43
- );
27
+ },
28
+ false ) );
44
29
}
45
30
46
31
/**
@@ -67,11 +52,10 @@ void testSolveSudoku(int[][] board, boolean expectedResult) {
67
52
* @param expectedResult True if the placement is valid, false otherwise.
68
53
*/
69
54
@ ParameterizedTest
70
- @ CsvSource ({
71
- "'5,3,0,0,7,0,0,0,0;6,0,0,1,9,5,0,0,0;0,9,8,0,0,0,0,6,0;8,0,0,0,6,0,0,0,3;4,0,0,8,0,3,0,0,1;7,0,0,0,2,0,0,0,6;0,6,0,0,0,0,2,8,0;0,0,0,4,1,9,0,0,5;0,0,0,0,8,0,0,7,9', 0, 2, 4, false" ,
72
- "'5,3,0,0,7,0,0,0,0;6,0,0,1,9,5,0,0,0;0,9,8,0,0,0,0,6,0;8,0,0,0,6,0,0,0,3;4,0,0,8,0,3,0,0,1;7,0,0,0,2,0,0,0,6;0,6,0,0,0,0,2,8,0;0,0,0,4,1,9,0,0,5;0,0,0,0,8,0,0,7,9', 0, 2, 9, true"
73
- })
74
- void testIsSafe (String boardString , int row , int col , int num , boolean expectedResult ) {
55
+ @ CsvSource ({"'5,3,0,0,7,0,0,0,0;6,0,0,1,9,5,0,0,0;0,9,8,0,0,0,0,6,0;8,0,0,0,6,0,0,0,3;4,0,0,8,0,3,0,0,1;7,0,0,0,2,0,0,0,6;0,6,0,0,0,0,2,8,0;0,0,0,4,1,9,0,0,5;0,0,0,0,8,0,0,7,9', 0, 2, 4, false" ,
56
+ "'5,3,0,0,7,0,0,0,0;6,0,0,1,9,5,0,0,0;0,9,8,0,0,0,0,6,0;8,0,0,0,6,0,0,0,3;4,0,0,8,0,3,0,0,1;7,0,0,0,2,0,0,0,6;0,6,0,0,0,0,2,8,0;0,0,0,4,1,9,0,0,5;0,0,0,0,8,0,0,7,9', 0, 2, 9, true" })
57
+ void
58
+ testIsSafe (String boardString , int row , int col , int num , boolean expectedResult ) {
75
59
int [][] board = parseBoard (boardString );
76
60
assertEquals (expectedResult , Sudoku .isSafe (board , row , col , num ));
77
61
}
0 commit comments