-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombiner_test.go
100 lines (84 loc) · 2.76 KB
/
combiner_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
package main
import "testing"
func combinerRectanglesSlice(combiner *Combiner) []Rectangle {
rectangles := make([]Rectangle, 0)
combiner.RectanglesEach(func(r Rectangle) {
rectangles = append(rectangles, r)
})
return rectangles
}
func TestRightCombinerRectangles(t *testing.T) {
combiner := Combiner{position: Position{1, 1}, direction: Right}
rectangles := combinerRectanglesSlice(&combiner)
validRectangles := []Rectangle{
{Position{0, 0}, 2, 3, nil},
{Position{2, 1}, 1, 1, nil},
}
for i := range validRectangles {
if !rectangles[i].Equals(validRectangles[i]) {
t.Errorf("Rectangle %d is not valid", i)
}
}
}
func TestBottomCombinerRectangles(t *testing.T) {
combiner := Combiner{position: Position{1, 1}, direction: Bottom}
rectangles := combinerRectanglesSlice(&combiner)
validRectangles := []Rectangle{
{Position{0, 0}, 3, 2, nil},
{Position{1, 2}, 1, 1, nil},
}
for i := range validRectangles {
if !rectangles[i].Equals(validRectangles[i]) {
t.Errorf("Rectangle %d is not valid", i)
}
}
}
func TestLeftCombinerRectangles(t *testing.T) {
combiner := Combiner{position: Position{1, 1}, direction: Left}
rectangles := combinerRectanglesSlice(&combiner)
validRectangles := []Rectangle{
{Position{1, 0}, 2, 3, nil},
{Position{0, 1}, 1, 1, nil},
}
for i := range validRectangles {
if !rectangles[i].Equals(validRectangles[i]) {
t.Errorf("Rectangle %d is not valid", i)
}
}
}
func TestTopCombinerRectangles(t *testing.T) {
combiner := Combiner{position: Position{1, 1}, direction: Top}
rectangles := combinerRectanglesSlice(&combiner)
validRectangles := []Rectangle{
{Position{0, 1}, 3, 2, nil},
{Position{1, 0}, 1, 1, nil},
}
for i := range validRectangles {
if !rectangles[i].Equals(validRectangles[i]) {
t.Errorf("Rectangle %d is not valid", i)
}
}
}
func TestCombinerNextToIngressPositions(t *testing.T) {
combiner := Combiner{
position: Position{2, 2},
direction: Right,
}
validPositionsRight := []Position{{0, 2}, {0, 1}, {0, 3}, {1, 0}, {1, 4}}
validPositionsBottom := []Position{{2, 0}, {1, 0}, {3, 0}, {0, 1}, {4, 1}}
validPositionsLeft := []Position{{4, 2}, {4, 1}, {4, 3}, {3, 0}, {3, 4}}
validPositionsTop := []Position{{2, 4}, {1, 4}, {3, 4}, {0, 3}, {4, 3}}
validPositions := [][]Position{validPositionsRight, validPositionsBottom, validPositionsLeft, validPositionsTop}
for i, direction := range []Direction{Right, Bottom, Left, Top} {
combiner.direction = direction
result := combiner.NextToIngressPositions()
if len(result) != len(validPositions[i]) {
t.Errorf("number of positions should be 5")
}
for j, p := range result {
if p != validPositions[i][j] {
t.Errorf("position %v of combiner with subtype %d does not match %v", p, combiner.direction, validPositions[i][j])
}
}
}
}