test/map_tests.c

changeset 53
e533c170bfb8
parent 52
34f50d0bada4
child 55
180bc6b18fec
--- a/test/map_tests.c	Fri Oct 05 16:59:14 2012 +0200
+++ b/test/map_tests.c	Mon Oct 08 12:29:27 2012 +0200
@@ -95,6 +95,47 @@
     UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
     UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
 
+    UCX_TEST_ASSERT(map->count == 5, "expected 5 remaining values");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0") != NULL, "element removed");
+
+    UCX_TEST_END
+    ucx_map_free(map);
+}
+
+UCX_TEST_IMPLEMENT(test_ucx_map_remove) {
+    UcxMap *map = ucx_map_new(4);
+
+    int td[5];
+    td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
+
+    ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */
+    ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
+    ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
+    ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */
+    ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */
+    UCX_TEST_BEGIN
+
+    td[0] = *((int*)ucx_map_cstr_remove(map, "Key0"));
+    td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
+    td[2] = *((int*)ucx_map_cstr_remove(map, "Key2"));
+    td[3] = *((int*)ucx_map_cstr_get(map, "KeY3"));
+    td[4] = *((int*)ucx_map_cstr_get(map, "KEY4"));
+    UCX_TEST_ASSERT(td[0] == 10, "failed key 0");
+    UCX_TEST_ASSERT(td[1] == 42, "failed key 1");
+    UCX_TEST_ASSERT(td[2] == 70, "failed key 2");
+    UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
+    UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
+
+    UCX_TEST_ASSERT(map->count == 3, "expected 3 remaining values");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0")==NULL, "element not removed");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key1")!=NULL, "element removed");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key2")==NULL, "element not removed");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KeY3")!=NULL, "element removed");
+    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KEY4")!=NULL, "element removed");
+
+    UCX_TEST_ASSERT(ucx_map_cstr_remove(map, "Key2") == NULL,
+            "subsequent remove call shall return NULL");
+
     UCX_TEST_END
     ucx_map_free(map);
 }

mercurial