-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatcher_test.go
executable file
·187 lines (148 loc) · 4.62 KB
/
matcher_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
182
183
184
185
186
187
package zinc_test
import (
"testing"
"github.com/SirMetathyst/zinc"
"github.com/stretchr/testify/assert"
"github.com/SirMetathyst/zinc/kit"
)
var (
matcherData = []struct {
allOf []uint
noneOf []uint
}{
{allOf: []uint{1, 2, 3}, noneOf: []uint{0, 10, 20}},
{allOf: []uint{0, 10, 2}, noneOf: []uint{99, 82, 10}},
}
)
func TestMatcherHasAllOf(t *testing.T) {
for _, ds := range matcherData {
// Act
m := zinc.AllOf(ds.allOf...)
has := m.HasAllOf(ds.allOf...)
// Assert
assert.True(t, has, "has all of must return true")
}
}
func TestMatcherAllOf(t *testing.T) {
for _, ds := range matcherData {
// Act
m := zinc.AllOf(ds.allOf...)
// Assert
assert.ElementsMatch(t, m.AllOfSlice(), ds.allOf, "returned all of slice does not match input data")
}
}
func TestMatcherHasNoneOf(t *testing.T) {
for _, ds := range matcherData {
// Act
m := zinc.NoneOf(ds.noneOf...)
has := m.HasNoneOf(ds.noneOf...)
// Assert
assert.True(t, has, "has none of must return true")
}
}
func TestMatcherNoneOf(t *testing.T) {
for _, ds := range matcherData {
// Act
m := zinc.NoneOf(ds.noneOf...)
// Assert
assert.ElementsMatch(t, m.NoneOfSlice(), ds.noneOf, "returned none of slice does not match input data")
}
}
func TestMatcherAllOfHash(t *testing.T) {
// Arrange, Act
m1 := zinc.AllOf(kit.LocalPosition2Key, kit.Velocity2Key)
m2 := zinc.AllOf(kit.Velocity2Key, kit.LocalPosition2Key)
// Assert
assert.Equal(t, m1.Hash(), m2.Hash(), "must share identical hash")
}
func TestMatcherNoneOfHash(t *testing.T) {
// Arrange, Act
m1 := zinc.NoneOf(kit.LocalPosition2Key, kit.Velocity2Key)
m2 := zinc.NoneOf(kit.Velocity2Key, kit.LocalPosition2Key)
// Assert
assert.Equal(t, m1.Hash(), m2.Hash(), "must share identical hash")
}
func TestMatcherHash(t *testing.T) {
// Arrange, Act
m1 := zinc.AllOf(kit.LocalPosition2Key, kit.Velocity2Key).
NoneOf(kit.LocalRotation2Key, kit.LocalScale2Key)
m2 := zinc.AllOf(kit.Velocity2Key, kit.LocalPosition2Key).
NoneOf(kit.LocalScale2Key, kit.LocalRotation2Key)
// Assert
assert.Equal(t, m1.Hash(), m2.Hash(), "must share identical hash")
}
func TestMatcherMatch(t *testing.T) {
t.Run("non-existing key", 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})
// Act
m := zinc.AllOf(0)
mv := m.Match(e, id)
// Assert
assert.False(t, mv, "must return false if matcher contains non-existing key")
})
t.Run("all of", 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})
// Act
m := zinc.AllOf(kit.LocalPosition2Key, kit.LocalRotation2Key)
mv := m.Match(e, id)
// Assert
assert.True(t, mv, "must return true if matcher contains all of given keys")
})
t.Run("none of", 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})
// Act
m := zinc.NoneOf(kit.LocalRotation2Key)
mv := m.Match(e, id)
// Assert
assert.True(t, mv, "must return true because matcher should not contain any of given keys")
})
t.Run("none of", 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})
// Act
m := zinc.NoneOf(kit.LocalRotation2Key)
mv := m.Match(e, id)
// Assert
assert.False(t, mv, "must return false because matcher contains some of given keys")
})
t.Run("all of/none of", 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})
// Act
m := zinc.AllOf(kit.LocalPosition2Key).NoneOf(kit.LocalRotation2Key)
mv := m.Match(e, id)
// Assert
assert.False(t, mv, "must return false to satisfy matcher")
})
}