tests/test_map.cpp

changeset 669
dce9b8450656
parent 668
d7129285ac32
child 677
b09aae58bba4
equal deleted inserted replaced
668:d7129285ac32 669:dce9b8450656
153 } 153 }
154 154
155 TEST(CxHashMap, BasicOperations) { 155 TEST(CxHashMap, BasicOperations) {
156 // create the map 156 // create the map
157 CxTestingAllocator allocator; 157 CxTestingAllocator allocator;
158 auto map = cxHashMapCreateForPointers(&allocator, 8); 158 auto map = cxHashMapCreate(&allocator, CX_STORE_POINTERS, 8);
159 159
160 // create a reference map 160 // create a reference map
161 std::unordered_map<std::string, std::string> refmap; 161 std::unordered_map<std::string, std::string> refmap;
162 162
163 // generate operations 163 // generate operations
197 EXPECT_TRUE(allocator.verify()); 197 EXPECT_TRUE(allocator.verify());
198 } 198 }
199 199
200 TEST(CxHashMap, RemoveViaIterator) { 200 TEST(CxHashMap, RemoveViaIterator) {
201 CxTestingAllocator allocator; 201 CxTestingAllocator allocator;
202 auto map = cxHashMapCreateForPointers(&allocator, 4); 202 auto map = cxHashMapCreate(&allocator, CX_STORE_POINTERS, 4);
203 203
204 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); 204 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1");
205 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); 205 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2");
206 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); 206 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3");
207 cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4"); 207 cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4");
226 EXPECT_TRUE(allocator.verify()); 226 EXPECT_TRUE(allocator.verify());
227 } 227 }
228 228
229 TEST(CxHashMap, RehashNotRequired) { 229 TEST(CxHashMap, RehashNotRequired) {
230 CxTestingAllocator allocator; 230 CxTestingAllocator allocator;
231 auto map = cxHashMapCreateForPointers(&allocator, 8); 231 auto map = cxHashMapCreate(&allocator, CX_STORE_POINTERS, 8);
232 232
233 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); 233 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1");
234 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); 234 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2");
235 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); 235 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3");
236 cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4"); 236 cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4");
246 EXPECT_TRUE(allocator.verify()); 246 EXPECT_TRUE(allocator.verify());
247 } 247 }
248 248
249 TEST(CxHashMap, Rehash) { 249 TEST(CxHashMap, Rehash) {
250 CxTestingAllocator allocator; 250 CxTestingAllocator allocator;
251 auto map = cxHashMapCreateForPointers(&allocator, 8); 251 auto map = cxHashMapCreate(&allocator, CX_STORE_POINTERS, 8);
252 252
253 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); 253 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1");
254 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); 254 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2");
255 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); 255 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3");
256 cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4"); 256 cxMapPut(map, cx_hash_key_str("key 4"), (void *) "val 4");
275 EXPECT_TRUE(allocator.verify()); 275 EXPECT_TRUE(allocator.verify());
276 } 276 }
277 277
278 TEST(CxHashMap, Clear) { 278 TEST(CxHashMap, Clear) {
279 CxTestingAllocator allocator; 279 CxTestingAllocator allocator;
280 auto map = cxHashMapCreateForPointers(&allocator, 0); 280 auto map = cxHashMapCreate(&allocator, CX_STORE_POINTERS, 0);
281 281
282 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1"); 282 cxMapPut(map, cx_hash_key_str("key 1"), (void *) "val 1");
283 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2"); 283 cxMapPut(map, cx_hash_key_str("key 2"), (void *) "val 2");
284 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3"); 284 cxMapPut(map, cx_hash_key_str("key 3"), (void *) "val 3");
285 285

mercurial