-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanager_test.go
executable file
·141 lines (116 loc) · 3.43 KB
/
manager_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
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 TestNewEntityManager(t *testing.T) {
// Arrange, Act
e := zinc.NewEntityManager()
// Assert
assert.NotNil(t, e, "must not return nil")
}
func TestEntityManagerCreateEntity(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
// Assert
test.CreateEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerHasEntity(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
// Assert
test.CreateEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
test.HasEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerDeleteEntity(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
// Assert
test.CreateEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
test.DeleteEntity(t, e, []zinc.EntityID{1, 2, 3})
test.DoesNotHaveEntities(t, e, []zinc.EntityID{1, 2, 3})
test.HasEntities(t, e, []zinc.EntityID{4, 5})
test.CreateEntities(t, e, []zinc.EntityID{3, 2, 1})
}
func TestEntityManagerDeleteEntities(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
// Assert
test.CreateEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
e.DeleteEntities()
test.DoesNotHaveEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
test.CreateEntities(t, e, []zinc.EntityID{5, 4, 3})
}
func TestEntityManagerEntities(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
// Assert
test.CreateEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
test.Entities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerReset(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
// Assert
test.CreateEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
test.HasEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
e.Reset()
test.DoesNotHaveEntities(t, e, []zinc.EntityID{1, 2, 3, 4, 5})
}
func TestEntityManagerRegisterComponent(t *testing.T) {
t.Run("register component type once", func(t *testing.T){
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
// Arrange
id := e.CreateEntity()
// Act
do := func(){
kit.SetLocalPosition2X(e, 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){
// Arrange
e := zinc.NewEntityManager()
// Act
do := func(){ kit.RegisterLocalPosition2ComponentWith(e) }
do()
// Assert
assert.Panics(t, do, "must panic if you try to register a component with the same key again")
})
}
func TestEntityManagerResetAll(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
// Arrange
id := e.CreateEntity()
// Act
e.ResetAll()
do := func(){ kit.SetLocalPosition2X(e, 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 TestEntityManagerGroup(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
kit.RegisterLocalPosition2ComponentWith(e)
// Assert
test.Group(t, e)
test.GroupCount(t, e, 1)
test.Group(t, e)
test.GroupCount(t, e, 1)
}
func TestEntityManagerCollector(t *testing.T) {
// Setup
e := zinc.NewEntityManager()
// Arrange, Act
c := e.CreateCollector(zinc.Added(kit.LocalPosition2Key))
// Assert
assert.NotNil(t, c, "entity manager must not return nil collector")
}