-
Notifications
You must be signed in to change notification settings - Fork 1
/
hst_naked_subset_test.go
91 lines (76 loc) · 2.95 KB
/
hst_naked_subset_test.go
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
package sudoku
import (
"testing"
)
func TestSubsetCellsWithNPossibilities(t *testing.T) {
grid, err := MutableLoadSDKFromFile(puzzlePath("nakedpair3.sdk"))
if err != nil {
t.Log("Failed to load nakedpair3.sdk")
t.Fail()
}
results := subsetCellsWithNPossibilities(2, grid.Col(DIM-1))
if len(results) != 1 {
t.Log("Didn't get right number of subset cells with n possibilities: ", len(results))
t.FailNow()
}
result := results[0]
if len(result) != 2 {
t.Log("Number of subset cells did not match k: ", len(result))
t.Fail()
}
if result[0].Row() != 6 || result[0].Col() != 8 || result[1].Row() != 7 || result[1].Col() != 8 {
t.Log("Subset cells came back with wrong cells: ", result)
t.Fail()
}
}
func TestNakedPairCol(t *testing.T) {
options := solveTechniqueTestHelperOptions{
targetCells: []CellRef{{2, 8}, {3, 8}, {4, 8}},
pointerCells: []CellRef{{6, 8}, {7, 8}},
targetSame: _GROUP_COL,
targetGroup: 8,
targetNums: IntSlice([]int{2, 3}),
description: "2 and 3 are only possible in (6,8) and (7,8), which means that they can't be in any other cell in column 8",
}
humanSolveTechniqueTestHelper(t, "nakedpair3.sdk", "Naked Pair Col", options)
techniqueVariantsTestHelper(t, "Naked Pair Col")
}
func TestNakedPairRow(t *testing.T) {
options := solveTechniqueTestHelperOptions{
transpose: true,
targetCells: []CellRef{{8, 2}, {8, 3}, {8, 4}},
pointerCells: []CellRef{{8, 6}, {8, 7}},
targetSame: _GROUP_ROW,
targetGroup: 8,
targetNums: IntSlice([]int{2, 3}),
description: "2 and 3 are only possible in (8,6) and (8,7), which means that they can't be in any other cell in row 8",
}
humanSolveTechniqueTestHelper(t, "nakedpair3.sdk", "Naked Pair Row", options)
techniqueVariantsTestHelper(t, "Naked Pair Row")
}
func TestNakedPairBlock(t *testing.T) {
options := solveTechniqueTestHelperOptions{
targetCells: []CellRef{{2, 0}, {2, 1}, {2, 2}},
pointerCells: []CellRef{{0, 0}, {0, 1}},
targetSame: _GROUP_BLOCK,
targetGroup: 0,
targetNums: IntSlice([]int{1, 2}),
description: "1 and 2 are only possible in (0,0) and (0,1), which means that they can't be in any other cell in block 0",
}
humanSolveTechniqueTestHelper(t, "nakedpairblock1.sdk", "Naked Pair Block", options)
techniqueVariantsTestHelper(t, "Naked Pair Block")
}
func TestNakedTriple(t *testing.T) {
//TODO: test for col and block as well
options := solveTechniqueTestHelperOptions{
targetCells: []CellRef{{4, 1}, {4, 2}, {4, 6}, {4, 7}},
pointerCells: []CellRef{{4, 3}, {4, 4}, {4, 5}},
targetSame: _GROUP_ROW,
targetGroup: 4,
targetNums: IntSlice([]int{3, 5, 8}),
description: "3, 5, and 8 are only possible in (4,3), (4,4), and (4,5), which means that they can't be in any other cell in row 4",
}
humanSolveTechniqueTestHelper(t, "nakedtriplet2.sdk", "Naked Triple Row", options)
techniqueVariantsTestHelper(t, "Naked Triple Row")
}
//TODO: test naked quad techniques. (We don't have an easy one that requires it off hand.)