-
Notifications
You must be signed in to change notification settings - Fork 10
/
engine_default_test.go
96 lines (77 loc) · 2.27 KB
/
engine_default_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
package ecs_test
import (
"testing"
"github.com/andygeiss/ecs"
)
func prepare() (e ecs.Engine, sys *mockupSystem) {
em := &mockupEntityManager{}
sm := &mockupSystemManager{}
system := &mockupSystem{State: ecs.StateEngineStop}
sm.Add(system)
engine := ecs.NewDefaultEngine(em, sm)
return engine, system
}
func TestDefaultEngine_Teardown_After_Setup_Should_Set_StateEngineStop(t *testing.T) {
engine, system := prepare()
engine.Setup()
// app.Run()
engine.Teardown()
if system.State != ecs.StateEngineStop {
t.Error("State should be correct")
}
}
func TestDefaultEngine_Run_Twice_Should_Increase_Counter_By_Two(t *testing.T) {
engine, system := prepare()
engine.Run()
if system.Counter != 1 {
t.Errorf("Counter should be 1, but got %d", system.Counter)
}
engine.Run()
if system.Counter != 2 {
t.Errorf("Counter should be 2, but got %d", system.Counter)
}
}
func TestDefaultEngine_Tick_Twice_Should_Increase_Counter_By_Two(t *testing.T) {
engine, system := prepare()
engine.Tick()
if system.Counter != 1 {
t.Errorf("Counter should be 1, but got %d", system.Counter)
}
engine.Run()
if system.Counter != 2 {
t.Errorf("Counter should be 2, but got %d", system.Counter)
}
}
/*
_ _ _
_ _| |_(_) |___
| | | | __| | / __|
| |_| | |_| | \__ \
\__,_|\__|_|_|___/
*/
type mockupEntityManager struct{}
func (m *mockupEntityManager) Add(entities ...*ecs.Entity) {}
func (m *mockupEntityManager) Entities() (entities []*ecs.Entity) { return nil }
func (m *mockupEntityManager) FilterByMask(mask uint64) (entities []*ecs.Entity) { return nil }
func (m *mockupEntityManager) FilterByNames(names ...string) (entities []*ecs.Entity) { return nil }
func (m *mockupEntityManager) Get(id string) (entity *ecs.Entity) { return nil }
func (m *mockupEntityManager) Remove(entity *ecs.Entity) {}
type mockupSystemManager struct {
systems []ecs.System
}
func (m *mockupSystemManager) Add(systems ...ecs.System) {
m.systems = append(m.systems, systems...)
}
func (m *mockupSystemManager) Systems() []ecs.System {
return m.systems
}
type mockupSystem struct {
Counter int
State int
}
func (s *mockupSystem) Process(entityManager ecs.EntityManager) (state int) {
s.Counter++
return ecs.StateEngineStop
}
func (s *mockupSystem) Setup() {}
func (s *mockupSystem) Teardown() {}