forked from unitoftime/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
53 lines (43 loc) · 1.06 KB
/
command_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
package ecs
import (
"testing"
)
func TestCommandExecution(t *testing.T) {
world := NewWorld()
cmd := NewCommand(world)
query := Query2[position, velocity](world)
// Write position
id := world.NewId()
pos := position{1, 1, 1}
WriteCmd(cmd, id, pos)
cmd.Execute()
// Check position and velocity
posOut, velOut := query.Read(id)
compare(t, *posOut, pos)
compare(t, velOut, nil)
// Write velocity
vel := velocity{2, 2, 2}
WriteCmd(cmd, id, vel)
cmd.Execute()
// Check position and velocity
posOut, velOut = query.Read(id)
compare(t, *posOut, pos)
compare(t, *velOut, vel)
compare(t, world.engine.count(position{}), 1)
compare(t, world.engine.count(position{}, velocity{}), 1)
compare(t, world.engine.count(position{}, velocity{}), 1)
compare(t, world.engine.count(acceleration{}), 0)
count := 0
query.MapId(func(id Id, p *position, v *velocity) {
count++
})
compare(t, count, 1)
// count = 0
// view := ViewAll2[position, velocity](world)
// for {
// _, _, _, ok := view.Iter()
// if !ok { break }
// count++
// }
// compare(t, count, 1)
}