-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_test.go
57 lines (51 loc) · 1.37 KB
/
system_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
package ecs
import (
"testing"
"github.com/stretchr/testify/assert"
)
type testSharedRegistryData struct {
IDs []int
TimesRun int
}
func TestGlobalRegistryFlow(t *testing.T) {
RegisterGlobalSystem(GlobalSystemInfo[BenchPos3]{
ExecPriority: 100,
ExecFlag: 80,
ExecBuilder: func(w *World, s *System[BenchPos3]) func(view *View[BenchPos3]) {
data := s.Data().(*testSharedRegistryData)
return func(view *View[BenchPos3]) {
data.TimesRun++
}
},
Initializer: func(w *World, sys *System[BenchPos3]) {
data := &testSharedRegistryData{
IDs: make([]int, 0, 2),
}
data.IDs = append(data.IDs, sys.ID())
w.Data().Set("tdata", data)
sys.SetData(data)
},
})
RegisterGlobalSystem(GlobalSystemInfo[BenchPos3]{
ExecPriority: 99,
ExecFlag: 80,
ExecBuilder: func(w *World, s *System[BenchPos3]) func(view *View[BenchPos3]) {
data := s.Data().(*testSharedRegistryData)
return func(view *View[BenchPos3]) {
data.TimesRun++
}
},
Initializer: func(w *World, sys *System[BenchPos3]) {
data := w.Data().Get("tdata").(*testSharedRegistryData)
data.IDs = append(data.IDs, sys.ID())
sys.SetData(data)
},
})
ww := NewWorld()
xdata := ww.Data().Get("tdata").(*testSharedRegistryData)
assert.Equal(t, 2, len(xdata.IDs))
ww.StepF(80)
assert.Equal(t, 2, xdata.TimesRun)
ww.StepF(80)
assert.Equal(t, 4, xdata.TimesRun)
}