sudoku - sorted_test.go
1 package sudoku
2
3 import "testing"
4
5 func TestFutoshiki(t *testing.T) {
6 t.Parallel()
7 g := []Constraint{
8 Unique{0, 1, 2, 3, 4},
9 Unique{5, 6, 7, 8, 9},
10 Unique{10, 11, 12, 13, 14},
11 Unique{15, 16, 17, 18, 19},
12 Unique{20, 21, 22, 23, 24},
13 Unique{0, 5, 10, 15, 20},
14 Unique{1, 6, 11, 16, 21},
15 Unique{2, 7, 12, 17, 22},
16 Unique{3, 8, 13, 18, 23},
17 Unique{4, 9, 14, 19, 24},
18 }
19 tests := []struct {
20 start, solution []int
21 solveable bool
22 chars int
23 constraints []Constraint
24 }{
25 {
26 make([]int, 25),
27 []int{
28 4, 2, 3, 1, 5,
29 5, 3, 1, 2, 4,
30 1, 5, 4, 3, 2,
31 2, 1, 5, 4, 3,
32 3, 4, 2, 5, 1,
33 },
34 true,
35 5,
36 append(g,
37 Sorted{1, 0, 5},
38 Sorted{3, 8, 9},
39 Sorted{13, 18, 17},
40 Sorted{16, 15, 20},
41 ),
42 },
43 {
44 make([]int, 25),
45 []int{
46 2, 5, 3, 1, 4,
47 1, 3, 4, 5, 2,
48 5, 4, 2, 3, 1,
49 3, 2, 1, 4, 5,
50 4, 1, 5, 2, 3,
51 },
52 true,
53 5,
54 append(g,
55 Sorted{2, 1},
56 Sorted{12, 7, 8},
57 Sorted{14, 9},
58 Sorted{17, 16, 15, 20},
59 Sorted{21, 16},
60 ),
61 },
62 }
63 for i, test := range tests {
64 solved := Solve(test.start, test.chars, test.constraints)
65 if test.solveable {
66 if solved {
67 for j, num := range test.start {
68 if num != test.solution[j] {
69 t.Errorf("solution found does not match solution given for test %d", i+1)
70 break
71 }
72 }
73 } else {
74 t.Errorf("didn't find solution in puzzle %d when solution expected", i+1)
75 }
76 }
77 }
78 }