-
Notifications
You must be signed in to change notification settings - Fork 1
/
entity_list_internal_test.go
executable file
·94 lines (65 loc) · 1.66 KB
/
entity_list_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
package zinc
import (
"testing"
"github.com/stretchr/testify/assert"
)
var (
entityListData = []EntityID {1, 2000, 20}
)
func TestNewEntityList(t *testing.T) {
// Arrange, Act
el := newEntityList()
// Assert
assert.NotNil(t, el, "must not return nil")
}
func TestEntityListAddEntity(t *testing.T) {
// Arrange
el := newEntityList()
for _, v := range entityListData {
// Act
v1 := el.AddEntity(v)
v2 := el.AddEntity(v)
// Assert
assert.Equal(t, true, v1, "adding a new entity that is not in the list should return true")
assert.Equal(t, false, v2, "adding an entity that has already been added should return false")
}
}
func TestEntityListDeleteEntity(t *testing.T) {
// Arrange
el := newEntityList()
for _, va := range entityListData {
el.AddEntity(va)
}
for _, v := range entityListData {
// Act
v1 := el.DeleteEntity(v)
v2 := el.DeleteEntity(v)
// Assert
assert.Equal(t, true, v1, "deleting an entity that has been added previously will return true")
assert.Equal(t, false, v2, "deleting an entity that does not exist should return false")
}
}
func TestEntityListHasEntity(t *testing.T) {
// Arrange
el := newEntityList()
for _, va := range entityListData {
el.AddEntity(va)
}
for _, v := range entityListData {
// Act
has := el.HasEntity(v)
// Assert
assert.Equalf(t, true, has, "must return true for id: %d", v)
}
}
func TestEntityListEntities(t *testing.T) {
// Arrange
el := newEntityList()
for _, v := range entityListData {
el.AddEntity(v)
}
// Act
entities := el.Entities()
// Assert
assert.ElementsMatch(t, entities, entityListData, "returned entities slice does not match input data")
}