-
Notifications
You must be signed in to change notification settings - Fork 1
/
manager_global_test.go
executable file
·133 lines (109 loc) · 3.17 KB
/
manager_global_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
package zinc_test
import (
"testing"
"github.com/SirMetathyst/zinc/test"
"github.com/SirMetathyst/zinc"
"github.com/SirMetathyst/zinc/kit"
"github.com/stretchr/testify/assert"
)
func TestEntityManagerCreateEntityGlobal(t *testing.T) {
// Reset
zinc.Reset()
// Assert
test.CreateEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerHasEntityGlobal(t *testing.T) {
// Reset
zinc.Reset()
// Assert
test.CreateEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
test.HasEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerDeleteEntityGlobal(t *testing.T) {
// Reset
zinc.Reset()
// Assert
test.CreateEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
test.DeleteEntityGlobal(t, []zinc.EntityID{1, 2, 3})
test.DoesNotHaveEntitiesGlobal(t, []zinc.EntityID{1, 2, 3})
test.HasEntitiesGlobal(t, []zinc.EntityID{4, 5})
test.CreateEntitiesGlobal(t, []zinc.EntityID{3, 2, 1})
}
func TestEntityManagerDeleteEntitiesGlobal(t *testing.T) {
// Reset
zinc.Reset()
// Assert
test.CreateEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
zinc.DeleteEntities()
test.DoesNotHaveEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerEntitiesGlobal(t *testing.T) {
// Reset
zinc.Reset()
// Assert
test.CreateEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
test.EntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerResetGlobal(t *testing.T) {
// Reset
zinc.Reset()
// Assert
test.CreateEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
test.HasEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
zinc.Reset()
test.DoesNotHaveEntitiesGlobal(t, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerRegisterComponentGlobal(t *testing.T) {
t.Run("register component type once", func(t *testing.T){
// Setup
zinc.ResetAll()
kit.RegisterLocalPosition2Component()
// Arrange
id := zinc.CreateEntity()
// Act
do := func(){
kit.SetLocalPosition2(id, kit.LocalPosition2Data{X: 10, Y: 20})
}
// Assert
assert.NotPanics(t, do, "should not panic because component type has been registered")
})
t.Run("register component type twice", func(t *testing.T){
// Setup
zinc.ResetAll()
// Act
do := func(){ kit.RegisterLocalPosition2Component() }
do()
// Assert
assert.Panics(t, do, "must panic if you try to register a component with the same key again")
})
}
func TestEntityManagerResetAllGlobal(t *testing.T) {
// Setup
zinc.ResetAll()
kit.RegisterLocalPosition2Component()
// Arrange
id := zinc.CreateEntity()
// Act
zinc.ResetAll()
do := func(){ kit.SetLocalPosition2(id, kit.LocalPosition2Data{X: 10, Y: 20}) }
// Assert
assert.Panics(t, do, "should panic because component type has been deleted due to reset all")
}
func TestEntityManagerGroupGlobal(t *testing.T) {
// Setup
zinc.ResetAll()
kit.RegisterLocalPosition2Component()
// Assert
test.GroupGlobal(t)
test.GroupCountGlobal(t, 1)
test.GroupGlobal(t)
test.GroupCountGlobal(t,1)
}
func TestEntityManagerCollectorGlobal(t *testing.T) {
// Setup
zinc.ResetAll()
// Arrange, Act
c := zinc.CreateCollector(zinc.Added(kit.LocalPosition2Key))
// Assert
assert.NotNil(t, c, "entity manager must not return nil collector")
}