-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrid_modification_test.go
101 lines (90 loc) · 2.2 KB
/
grid_modification_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
100
101
package sudoku
import (
"testing"
)
func TestCopyWithModifications(t *testing.T) {
sourceGrid := NewGrid()
sourceGrid.MutableCell(0, 0).SetMark(1, true)
sourceGrid.MutableCell(0, 0).SetExcluded(1, true)
sourceGridRO := sourceGrid.Copy()
if !isGridImpl(sourceGridRO) {
t.Fatal("Expected grid.Copy to return an immutable grid")
}
gridFive := NewGrid()
gridFive.MutableCell(0, 0).SetNumber(5)
gridMarks := NewGrid()
gridMarksCell := gridMarks.MutableCell(0, 0)
gridMarksCell.SetMark(2, true)
gridMarksCell.SetMark(1, false)
gridExcludes := sourceGrid.MutableCopy()
gridExcludesCell := gridExcludes.MutableCell(0, 0)
gridExcludesCell.SetExcluded(2, true)
gridExcludesCell.SetExcluded(1, false)
tests := []struct {
modifications GridModification
expected Grid
description string
}{
{
GridModification{
&CellModification{
Cell: CellRef{0, 0},
Number: 5,
},
},
gridFive,
"Single valid number",
},
{
GridModification{
&CellModification{
Cell: CellRef{0, 0},
Number: DIM + 1,
},
},
sourceGrid,
"Single invalid number",
},
{
GridModification{
&CellModification{
Cell: CellRef{0, 0},
Number: -1,
MarksChanges: map[int]bool{
1: false,
2: true,
DIM + 1: true,
},
},
},
gridMarks,
"Marks",
},
{
GridModification{
&CellModification{
Cell: CellRef{0, 0},
Number: -1,
ExcludesChanges: map[int]bool{
1: false,
2: true,
DIM + 1: true,
},
},
},
gridExcludes,
"Excludes",
},
}
for i, test := range tests {
result := sourceGrid.CopyWithModifications(test.modifications)
if result.Diagram(true) != test.expected.Diagram(true) {
t.Error("Test", i, "failed", test.description, "Got", result.Diagram(true), "expected", test.expected.Diagram(true))
}
//Also test the non-mutalbe grid implementation
nonMutableResult := sourceGridRO.CopyWithModifications(test.modifications)
if result.Diagram(true) != test.expected.Diagram(true) {
t.Error("Test", i, "failed with non-mutable copy", test.description, "Got", nonMutableResult.Diagram(true), "expected", test.expected.Diagram(true))
}
}
}