forked from blampe/goat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iter_test.go
90 lines (79 loc) · 1.3 KB
/
iter_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
package goat
import (
"testing"
qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp"
)
var eq = qt.CmpEquals(
cmp.Comparer(func(i1, i2 Index) bool {
return i1.X == i2.X && i1.Y == i2.Y
}),
)
func TestIterators(t *testing.T) {
c := qt.New(t)
tests := []struct {
iterator chan Index
expected []Index
}{
// UpDown
// 1 3
// 2 4
{
iterator: upDown(2, 2),
expected: []Index{
{0, 0},
{0, 1},
{1, 0},
{1, 1},
},
},
// leftRight
// 1 2
// 3 4
{
iterator: leftRight(2, 2),
expected: []Index{
{0, 0},
{1, 0},
{0, 1},
{1, 1},
},
},
// DiagUp
// 1 3
// 2 5
// 4 6
{
iterator: diagUp(2, 3),
expected: []Index{
{0, 0}, // x + y == 0
{0, 1}, // x + y == 1
{1, 0}, // x + y == 1
{0, 2}, // x + y == 2
{1, 1}, // x + y == 2
{1, 2}, // x + y == 3
},
},
// DiagDown
// 2 4 6
// 1 3 5
{
iterator: diagDown(3, 2),
expected: []Index{
{0, 1}, // x - y == -1
{0, 0}, // x - y == 0
{1, 1}, // x - y == 0
{1, 0}, // x - y == 1
{2, 1}, // x - y == 1
{2, 0}, // x - y == 2
},
},
}
for _, tt := range tests {
result := make([]Index, 0, len(tt.expected))
for i := range tt.iterator {
result = append(result, i)
}
c.Assert(result, eq, tt.expected)
}
}