-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathtest_ecs_entity_list.h
162 lines (134 loc) · 3.04 KB
/
test_ecs_entity_list.h
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef TEST_ECS_ENTITY_LIST_H
#define TEST_ECS_ENTITY_LIST_H
#include "tests/test_macros.h"
#include "../storage/storage.h"
#include "core/os/os.h"
namespace godex_entity_list_tests {
TEST_CASE("[Modules][ECS] Test ECS EntityList.") {
EntityList changed;
{
// Make sure only one time the entity is stored, even if notified multiple
// times.
changed.insert(1);
changed.insert(1);
changed.insert(1);
changed.insert(1);
uint32_t count = 0;
changed.for_each([&](EntityID p_entity) {
count += 1;
});
CHECK(count == 1);
// Make sure on updated the entity is removed.
changed.remove(1);
count = 0;
changed.for_each([&](EntityID p_entity) {
count += 1;
});
CHECK(count == 0);
}
// Test clear.
{
changed.remove(1);
changed.remove(2);
changed.clear();
uint32_t count = 0;
changed.for_each([&](EntityID p_entity) {
count += 1;
});
CHECK(count == 0);
CHECK(changed.is_empty());
}
changed.clear();
CHECK(changed.is_empty());
// Remove the `EntityID` 1 as soon as possible.
{
changed.insert(0);
changed.insert(1);
changed.insert(2);
changed.insert(3);
// Using a vector because the order is not guaranteed by this container.
LocalVector<bool> checked;
checked.resize(4);
checked[0] = false;
checked[1] = true; // This get removed
checked[2] = false;
checked[3] = false;
changed.for_each([&](EntityID p_entity) {
checked[p_entity] = true;
changed.remove(1);
});
CHECK(checked[0]);
CHECK(checked[1]);
CHECK(checked[2]);
CHECK(checked[3]);
}
changed.clear();
CHECK(changed.is_empty());
// Remove the `EntityID` 1, while processing.
{
changed.insert(0);
changed.insert(1);
changed.insert(2);
changed.insert(3);
LocalVector<bool> checked;
checked.resize(4);
checked[0] = false;
checked[1] = true; // This get removed
checked[2] = false;
checked[3] = false;
changed.for_each([&](EntityID p_entity) {
checked[p_entity] = true;
if (p_entity == EntityID(1)) {
changed.remove(1);
}
});
CHECK(checked[0]);
CHECK(checked[1]);
CHECK(checked[2]);
CHECK(checked[3]);
}
changed.clear();
CHECK(changed.is_empty());
// Remove the `EntityID` 1, when already processed.
{
changed.insert(0);
changed.insert(1);
changed.insert(2);
changed.insert(3);
changed.insert(4);
LocalVector<bool> checked;
checked.resize(5);
checked[0] = false;
checked[1] = true; // This get removed
checked[2] = false;
checked[3] = false;
checked[4] = false;
changed.for_each([&](EntityID p_entity) {
checked[p_entity] = true;
if (p_entity == EntityID(2)) {
changed.remove(1);
}
});
CHECK(checked[0]);
CHECK(checked[1]);
CHECK(checked[2]);
CHECK(checked[3]);
CHECK(checked[4]);
}
changed.clear();
CHECK(changed.is_empty());
// Test self consuming for_each.
{
changed.insert(4);
changed.insert(2);
changed.insert(3);
changed.insert(1);
changed.insert(0);
changed.for_each([&](EntityID p_entity) {
changed.remove(p_entity);
});
CHECK(changed.is_empty());
}
}
} // namespace godex_entity_list_tests
#endif