tests/test_hash_map.c

changeset 1510
89cf6b4a5792
parent 1483
97a6cf1520ba
equal deleted inserted replaced
1509:0437871200d6 1510:89cf6b4a5792
307 CX_TEST(test_hash_map_remove_via_iterator) { 307 CX_TEST(test_hash_map_remove_via_iterator) {
308 CxTestingAllocator talloc; 308 CxTestingAllocator talloc;
309 cx_testing_allocator_init(&talloc); 309 cx_testing_allocator_init(&talloc);
310 CxAllocator *allocator = &talloc.base; 310 CxAllocator *allocator = &talloc.base;
311 CX_TEST_DO { 311 CX_TEST_DO {
312 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 4); 312 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 3);
313 313
314 cxMapPut(map, "key 1", (void *) "val 1"); 314 cxMapPut(map, "key 1", (void *) "val 1");
315 cxMapPut(map, "key 2", (void *) "val 2"); 315 cxMapPut(map, "key 2", (void *) "val 2");
316 cxMapPut(map, "key 3", (void *) "val 3"); 316 cxMapPut(map, "key 3", (void *) "val 3");
317 cxMapPut(map, "key 4", (void *) "val 4"); 317 cxMapPut(map, "key 4", (void *) "val 4");
318 cxMapPut(map, "key 5", (void *) "val 5"); 318 cxMapPut(map, "key 5", (void *) "val 5");
319 cxMapPut(map, "key 6", (void *) "val 6"); 319 cxMapPut(map, "key 6", (void *) "val 6");
320 cxMapPut(map, "key 7", (void *) "val 7");
321 cxMapPut(map, "key 8", (void *) "val 8");
322 cxMapPut(map, "key 9", (void *) "val 9");
320 323
321 CxMapIterator iter = cxMapIterator(map); 324 CxMapIterator iter = cxMapIterator(map);
322 cx_foreach(CxMapEntry*, entry, iter) { 325 cx_foreach(CxMapEntry*, entry, iter) {
323 if (((const char *)entry->key->data)[4] % 2 == 1) cxIteratorFlagRemoval(iter); 326 if (((const char *)entry->key->data)[4] % 2 == 1) cxIteratorFlagRemoval(iter);
324 } 327 }
325 CX_TEST_ASSERT(cxMapSize(map) == 3); 328 CX_TEST_ASSERT(cxMapSize(map) == 4);
326 CX_TEST_ASSERT(iter.elem_count == 3); 329 CX_TEST_ASSERT(iter.elem_count == 4);
327 CX_TEST_ASSERT(iter.index == map->collection.size); 330 CX_TEST_ASSERT(iter.index == map->collection.size);
328 331
329 CX_TEST_ASSERT(cxMapGet(map, "key 1") == NULL); 332 CX_TEST_ASSERT(cxMapGet(map, "key 1") == NULL);
330 CX_TEST_ASSERT(cxMapGet(map, "key 2") != NULL); 333 CX_TEST_ASSERT(cxMapGet(map, "key 2") != NULL);
331 CX_TEST_ASSERT(cxMapGet(map, "key 3") == NULL); 334 CX_TEST_ASSERT(cxMapGet(map, "key 3") == NULL);
332 CX_TEST_ASSERT(cxMapGet(map, "key 4") != NULL); 335 CX_TEST_ASSERT(cxMapGet(map, "key 4") != NULL);
333 CX_TEST_ASSERT(cxMapGet(map, "key 5") == NULL); 336 CX_TEST_ASSERT(cxMapGet(map, "key 5") == NULL);
334 CX_TEST_ASSERT(cxMapGet(map, "key 6") != NULL); 337 CX_TEST_ASSERT(cxMapGet(map, "key 6") != NULL);
338 CX_TEST_ASSERT(cxMapGet(map, "key 7") == NULL);
339 CX_TEST_ASSERT(cxMapGet(map, "key 8") != NULL);
340 CX_TEST_ASSERT(cxMapGet(map, "key 9") == NULL);
335 341
336 cxMapFree(map); 342 cxMapFree(map);
337 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); 343 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
338 } 344 }
339 cx_testing_allocator_destroy(&talloc); 345 cx_testing_allocator_destroy(&talloc);

mercurial