-
Notifications
You must be signed in to change notification settings - Fork 1
/
context_internal_test.go
executable file
·108 lines (75 loc) · 2.3 KB
/
context_internal_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
97
98
99
100
101
102
103
104
105
106
107
108
package zinc
import (
"testing"
"github.com/stretchr/testify/assert"
)
func componentFunc(rkey *uint, rid *EntityID) func(key uint, id EntityID) {
return func(key uint, id EntityID) {
*rid = id
*rkey = key
}
}
func hasEntityFunc(rid *EntityID) func(id EntityID) bool {
return func(id EntityID) bool {
*rid = id
return true
}
}
func TestNewContext(t *testing.T) {
// Arrange, Assert
ctx := newContext(nil, nil, nil, nil)
// Assert
assert.NotNil(t, ctx, "must not return nil")
}
func TestContextComponentAdded(t *testing.T) {
// Arrange
returnKey := uint(0)
returnID := EntityID(0)
expectedKey := uint(20)
expectedID := EntityID(10)
ctx := newContext(componentFunc(&returnKey, &returnID), nil, nil, nil)
// Act
ctx.ComponentAdded(expectedKey, expectedID)
// Assert
assert.Equal(t, expectedKey, returnKey, "returned key does match expected key")
assert.Equal(t, expectedID, returnID, "returned id does match expected id")
}
func TestContextComponentUpdated(t *testing.T) {
// Arrange
returnKey := uint(0)
returnID := EntityID(0)
expectedKey := uint(20)
expectedID := EntityID(10)
ctx := newContext(nil, nil, componentFunc(&returnKey, &returnID), nil)
// Act
ctx.ComponentUpdated(expectedKey, expectedID)
// Assert
assert.Equal(t, expectedKey, returnKey, "returned key does match expected key")
assert.Equal(t, expectedID, returnID, "returned id does match expected id")
}
func TestContextComponentDeleted(t *testing.T) {
// Arrange
returnKey := uint(0)
returnID := EntityID(0)
expectedKey := uint(20)
expectedID := EntityID(10)
ctx := newContext(nil, componentFunc(&returnKey, &returnID), nil, nil)
// Act
ctx.ComponentDeleted(expectedKey, expectedID)
// Assert
assert.Equal(t, expectedKey, returnKey, "returned key does match expected key")
assert.Equal(t, expectedID, returnID, "returned id does match expected id")
}
func TestContextHasEntity(t *testing.T) {
// Arrange
returnID := EntityID(0)
returnState := false
expectedID := EntityID(10)
expectedState := true
ctx := newContext(nil, nil, nil, hasEntityFunc(&returnID))
// Act
returnState = ctx.HasEntity(expectedID)
// Assert
assert.Equal(t, expectedState, returnState, "return state does match expected return state")
assert.Equal(t, expectedID, returnID, "returned id does match expected id")
}