MCPcopy Create free account
hub / github.com/crownengine/crown / test_hash_map

Function test_hash_map

src/core/unit_tests.cpp:155–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155static void test_hash_map()
156{
157 memory_globals::init();
158 Allocator &a = default_allocator();
159 {
160 HashMap<s32, s32> m(a);
161
162 ENSURE(hash_map::size(m) == 0);
163 ENSURE(hash_map::get(m, 0, 42) == 42);
164 ENSURE(!hash_map::has(m, 10));
165
166 for (s32 i = 0; i < 100; ++i)
167 hash_map::set(m, i, i*i);
168 for (s32 i = 0; i < 100; ++i)
169 ENSURE(hash_map::get(m, i, 0) == i*i);
170
171 hash_map::remove(m, 20);
172 ENSURE(!hash_map::has(m, 20));
173
174 hash_map::remove(m, 2000);
175 ENSURE(!hash_map::has(m, 2000));
176
177 hash_map::remove(m, 50);
178 ENSURE(!hash_map::has(m, 50));
179
180 hash_map::clear(m);
181
182 for (s32 i = 0; i < 100; ++i)
183 ENSURE(!hash_map::has(m, i));
184 }
185 {
186 HashMap<s32, s32> m(a);
187
188 for (s32 i = 0; i < 12; ++i) {
189 s32 key = 12 + i;
190 hash_map::set(m, key, 99);
191 hash_map::set(m, i, i);
192 hash_map::remove(m, key);
193 }
194
195 ENSURE(hash_map::size(m) == 12);
196
197 for (s32 i = 0; i < 12; ++i)
198 ENSURE(hash_map::get(m, i, 0) == i);
199 }
200 {
201 HashMap<s32, s32> m(a);
202 hash_map_internal::grow(m);
203 ENSURE(hash_map::capacity(m) == 16);
204
205 hash_map::set(m, 0, 7);
206
207 hash_map::set(m, 1, 1);
208
209 for (s32 i = 2; i < 150; ++i) {
210 hash_map::set(m, i, 2);
211 ENSURE(hash_map::has(m, 0));
212 ENSURE(hash_map::has(m, 1));

Callers

nothing calls this directly

Calls 9

getFunction · 0.85
setClass · 0.85
initFunction · 0.70
clearFunction · 0.70
shutdownFunction · 0.70
sizeFunction · 0.50
hasFunction · 0.50
removeFunction · 0.50
capacityFunction · 0.50

Tested by

no test coverage detected