-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneighbors_test.go
47 lines (43 loc) · 1.02 KB
/
neighbors_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
package egriden
import (
"slices"
"testing"
)
func TestNeighbors(t *testing.T) {
lv := NewBaseLevel("test")
l1 := lv.CreateSimpleGridLayerOnTop("layer 1", 10, 5, 5, Sparse, 0, 0)
c1 := l1.CellAt(0, 1)
n := c1.GetNeighbors(Bishop, true, true)
// | n
// | c
// | n
if len(n) != 3 {
t.Errorf("Wrong neighbors slice len in: %v", n)
}
if !slices.Contains(n, c1) {
t.Errorf("Missing origin cell in: %v", n)
}
if !slices.Contains(n, l1.CellAt(1, 0)) || !slices.Contains(n, l1.CellAt(1, 2)) {
t.Errorf("Missing cell in: %v", n)
}
l1.AddGobject(NewBaseGobject("hello!", EmptySpritePack()).Build(), 1, 1)
// |
// | o
// | c
n2 := l1.CellAt(2, 2).GetNeighborsSetFunc(King, false, true,
func(c Cell) bool {
if c.HasGobject() && c.Gobject().Name() == "hello!" {
return true
}
return false
},
)
if len(n2) != 1 {
t.Errorf("Wrong neighbors set len of: %v", n2)
}
for k := range n2 {
if k.HasGobject() && k.Gobject().Name() != "hello!" {
t.Errorf("Wrong gobject in neighbor set: %v", n2)
}
}
}