-
Notifications
You must be signed in to change notification settings - Fork 1
/
group_test.go
executable file
·181 lines (139 loc) · 4.56 KB
/
group_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package zinc_test
import (
"testing"
"github.com/SirMetathyst/zinc/kit"
"github.com/stretchr/testify/assert"
"github.com/SirMetathyst/zinc"
)
func TestGroupHandleEntitySilently(t *testing.T) {
t.Run("handle entity silently", func(t *testing.T){
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
// Arrange
id := e.CreateEntity()
kit.SetLocalPosition2X(e, id, kit.LocalPosition2Data{X: 10, Y: 10})
called := false
// Act
g := e.Group(zinc.AllOf(kit.LocalPosition2Key, kit.LocalRotation2Key))
g.HandleEntityAdded(func (key uint, id zinc.EntityID){
called = true
})
// Assert
assert.Equal(t, 0, len(g.Entities()), "group should not contain any entities")
assert.False(t, called, "handle entity added should not be called")
})
t.Run("handle entity silently", func(t *testing.T){
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
kit.RegisterLocalRotation2ComponentWith(e)
// Arrange
id := e.CreateEntity()
kit.SetLocalPosition2X(e, id, kit.LocalPosition2Data{X: 10, Y: 10})
kit.SetLocalRotation2X(e, id, kit.LocalRotation2Data{X: 10, Y: 10})
called := false
// Act
g := e.Group(zinc.AllOf(kit.LocalPosition2Key, kit.LocalRotation2Key))
g.HandleEntityAdded(func (key uint, id zinc.EntityID){
called = true
})
// Assert
assert.Equal(t, 1, len(g.Entities()), "group should contain 1 entity")
assert.False(t, called, "handle entity added should not be called")
})
}
func TestGroupHandleEntity(t *testing.T) {
t.Run("handle entity", func(t *testing.T){
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
// Arrange
called := false
g := e.Group(zinc.AllOf(kit.LocalPosition2Key, kit.LocalRotation2Key))
g.HandleEntityAdded(func (key uint, id zinc.EntityID){
called = true
})
// Act
id := e.CreateEntity()
kit.SetLocalPosition2X(e, id, kit.LocalPosition2Data{X: 10, Y: 10})
// Assert
assert.Equal(t, 0, len(g.Entities()), "group should not contain any entities")
assert.False(t, called, "handle entity added should not be called")
})
t.Run("handle entity", func(t *testing.T){
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
kit.RegisterLocalRotation2ComponentWith(e)
// Arrange
called := false
g := e.Group(zinc.AllOf(kit.LocalPosition2Key, kit.LocalRotation2Key))
g.HandleEntityAdded(func (key uint, id zinc.EntityID){
called = true
})
// Act
id := e.CreateEntity()
kit.SetLocalPosition2X(e, id, kit.LocalPosition2Data{X: 10, Y: 10})
kit.SetLocalRotation2X(e, id, kit.LocalRotation2Data{X: 10, Y: 10})
// Assert
assert.Equal(t, 1, len(g.Entities()), "group should contain 1 entity")
assert.True(t, called, "handle entity added should be called")
})
}
func TestGroupUpdateEntity(t *testing.T) {
t.Run("update entity", func(t *testing.T){
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
// Arrange
called := false
g := e.Group(zinc.AllOf(kit.LocalPosition2Key))
g.HandleEntityUpdated(func(key uint, id zinc.EntityID){
called = true
})
// Act
id := e.CreateEntity()
kit.SetLocalPosition2X(e, id, kit.LocalPosition2Data{X: 10, Y: 10})
kit.SetLocalPosition2X(e, id, kit.LocalPosition2Data{X: 10, Y: 20})
// Assert
assert.Equal(t, 1, len(g.Entities()), "group should contain 1 entity")
assert.True(t, called, "handle entity updated should have been called")
})
}
func TestGroupDeleteEntity(t *testing.T) {
t.Run("delete entity", func(t *testing.T){
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
// Arrange
called := false
g := e.Group(zinc.AllOf(kit.LocalPosition2Key))
g.HandleEntityDeleted(func(key uint, id zinc.EntityID){
called = true
})
// Act
id := e.CreateEntity()
kit.SetLocalPosition2X(e, id, kit.LocalPosition2Data{X: 10, Y: 10})
kit.DeleteLocalPosition2X(e, id)
// Assert
assert.Equal(t, 0, len(g.Entities()), "group should not contain any entities")
assert.True(t, called, "handle entity deleted should have been called")
})
}
func TestGroupHasEntity(t *testing.T) {
t.Run("has entity", func(t *testing.T){
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
// Arrange
g := e.Group(zinc.AllOf(kit.LocalPosition2Key))
// Act
id := e.CreateEntity()
kit.SetLocalPosition2X(e, id, kit.LocalPosition2Data{X: 10, Y: 10})
has := g.HasEntity(id)
// Assert
assert.Equal(t, 1, len(g.Entities()), "group should contain 1 entity")
assert.True(t, has, "should return true")
})
}