-
Notifications
You must be signed in to change notification settings - Fork 23
/
entry_test.go
61 lines (49 loc) · 1.26 KB
/
entry_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
package donburi_test
import (
"testing"
"github.com/yohamta/donburi"
)
func TestSetValue(t *testing.T) {
var (
transform = donburi.NewComponentType[transformData]()
)
world := donburi.NewWorld()
a := world.Create(transform)
entryA := world.Entry(a)
trData := transformData{
Position: vec2f{10, 20},
}
donburi.SetValue(entryA, transform, trData)
got := donburi.GetValue[transformData](entryA, transform)
if got != trData {
t.Errorf("got: %v, want: %v", got, trData)
}
}
func TestGetComponents(t *testing.T) {
var (
transform = donburi.NewComponentType[transformData]()
velocity = donburi.NewComponentType[velocityData]()
tag = donburi.NewTag().SetName("tag")
)
world := donburi.NewWorld()
a := world.Create(transform, velocity, tag)
entryA := world.Entry(a)
trData := transformData{
Position: vec2f{10, 20},
}
veData := velocityData{
Velocity: vec2f{30, 40},
}
donburi.SetValue(entryA, transform, trData)
donburi.SetValue(entryA, velocity, veData)
gots := donburi.GetComponents(entryA)
wants := []interface{}{trData, veData, donburi.Tag("")}
if len(gots) != len(wants) {
t.Fatalf("got: %v, want: %v", gots, wants)
}
for i, got := range gots {
if got != wants[i] {
t.Errorf("got: %v, want: %v", got, wants[i])
}
}
}