-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine_test.go
45 lines (34 loc) · 970 Bytes
/
engine_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
package ecs_test
import (
"testing"
"gotest.tools/assert"
"jordiburgos.com/officestruggle/constants"
"jordiburgos.com/officestruggle/ecs"
"jordiburgos.com/officestruggle/game"
)
var engine = ecs.NewEngine()
var gs = game.NewGameState(engine)
func TestGetEntities(t *testing.T) {
ents1 := GetEntitiesFn()
ents2 := GetEntitiesWithFilterFn()
assert.Equal(t, len(ents1), len(ents2))
}
func GetEntitiesFn() ecs.EntityList {
return engine.Entities.GetEntities([]string{constants.Position, constants.Apparence})
}
func BenchmarkGetEntities(b *testing.B) {
for i := 0; i < b.N; i++ {
GetEntitiesFn()
}
}
func GetEntitiesWithFilterFn() ecs.EntityList {
return engine.Entities.GetEntitiesWithFilter(filter)
}
func filter(entity *ecs.Entity) bool {
return entity.HasComponent(constants.Position) && entity.HasComponent(constants.Apparence)
}
func BenchmarkGetEntitiesWithFilter(b *testing.B) {
for i := 0; i < b.N; i++ {
GetEntitiesWithFilterFn()
}
}