-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhst_swordfish_test.go
99 lines (73 loc) · 3 KB
/
hst_swordfish_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
92
93
94
95
96
97
98
99
package sudoku
import (
"testing"
)
//TODO: test a few more puzzles to make sure I'm exercising it correctly.
func swordfishExampleGrid(t *testing.T) MutableGrid {
puzzleName := "swordfish_example.sdk"
grid, err := MutableLoadSDKFromFile(puzzlePath(puzzleName))
if err != nil {
t.Fatal("Couldn't load puzzle ", puzzleName)
}
//Set up the grid correctly for the Swordfish technique to work. The
//example we use is a grid that has other work done to exclude
//possibilities from certain cells.
//TODO: it's a smell that there's no way to serialize and load up a grid
//with extra excludes set.
excludedConfig := map[CellRef]IntSlice{
{0, 0}: {1, 8},
{1, 3}: {1},
{1, 4}: {1, 8},
{2, 3}: {1},
{2, 5}: {1, 8},
{3, 0}: {2, 8},
{4, 0}: {7},
{4, 1}: {7},
{7, 3}: {1, 6},
{7, 5}: {1},
}
for ref, ints := range excludedConfig {
cell := ref.MutableCell(grid)
for _, exclude := range ints {
cell.SetExcluded(exclude, true)
}
}
return grid
}
func TestSwordfishCol(t *testing.T) {
techniqueVariantsTestHelper(t, "Swordfish Col")
grid := swordfishExampleGrid(t)
options := solveTechniqueTestHelperOptions{
targetCells: []CellRef{{1, 1}, {5, 4}},
pointerCells: []CellRef{{1, 0}, {1, 5}, {5, 3}, {5, 5}, {8, 0}, {8, 3}},
targetNums: IntSlice{1},
description: "1 is only possible in two cells each in three different columns, all of which align onto three rows, which means that 1 can't be in any of the other cells in those rows ((1,1) and (5,4))",
}
options.stepsToCheck.grid = grid
//TODO: it's not possible to just pass in an override grid to humanSolveTechniqueTestHelper as
//is, because we're overloading passing it to stepsToCheck. That's a smell.
grid, solver, steps := humanSolveTechniqueTestHelperStepGenerator(t, "NOOP", "Swordfish Col", options)
options.stepsToCheck.grid = grid
options.stepsToCheck.solver = solver
options.stepsToCheck.steps = steps
humanSolveTechniqueTestHelper(t, "NOOP", "Swordfish Col", options)
}
func TestSwordfishRow(t *testing.T) {
techniqueVariantsTestHelper(t, "Swordfish Row")
grid := swordfishExampleGrid(t)
grid = grid.(*mutableGridImpl).transpose()
options := solveTechniqueTestHelperOptions{
targetCells: []CellRef{{1, 1}, {4, 5}},
pointerCells: []CellRef{{0, 1}, {5, 1}, {3, 5}, {5, 5}, {0, 8}, {3, 8}},
targetNums: IntSlice{1},
description: "1 is only possible in two cells each in three different rows, all of which align onto three columns, which means that 1 can't be in any of the other cells in those columns ((1,1) and (4,5))",
}
options.stepsToCheck.grid = grid
//TODO: it's not possible to just pass in an override grid to humanSolveTechniqueTestHelper as
//is, because we're overloading passing it to stepsToCheck. That's a smell.
grid, solver, steps := humanSolveTechniqueTestHelperStepGenerator(t, "NOOP", "Swordfish Row", options)
options.stepsToCheck.grid = grid
options.stepsToCheck.solver = solver
options.stepsToCheck.steps = steps
humanSolveTechniqueTestHelper(t, "NOOP", "Swordfish Row", options)
}