test/map_tests.c

changeset 53
e533c170bfb8
parent 52
34f50d0bada4
child 55
180bc6b18fec
equal deleted inserted replaced
52:34f50d0bada4 53:e533c170bfb8
93 UCX_TEST_ASSERT(td[1] == 42, "failed key 1"); 93 UCX_TEST_ASSERT(td[1] == 42, "failed key 1");
94 UCX_TEST_ASSERT(td[2] == 70, "failed key 2"); 94 UCX_TEST_ASSERT(td[2] == 70, "failed key 2");
95 UCX_TEST_ASSERT(td[3] == 11200, "failed key 3"); 95 UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
96 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4"); 96 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
97 97
98 UCX_TEST_ASSERT(map->count == 5, "expected 5 remaining values");
99 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0") != NULL, "element removed");
100
101 UCX_TEST_END
102 ucx_map_free(map);
103 }
104
105 UCX_TEST_IMPLEMENT(test_ucx_map_remove) {
106 UcxMap *map = ucx_map_new(4);
107
108 int td[5];
109 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
110
111 ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */
112 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
113 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
114 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */
115 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */
116 UCX_TEST_BEGIN
117
118 td[0] = *((int*)ucx_map_cstr_remove(map, "Key0"));
119 td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
120 td[2] = *((int*)ucx_map_cstr_remove(map, "Key2"));
121 td[3] = *((int*)ucx_map_cstr_get(map, "KeY3"));
122 td[4] = *((int*)ucx_map_cstr_get(map, "KEY4"));
123 UCX_TEST_ASSERT(td[0] == 10, "failed key 0");
124 UCX_TEST_ASSERT(td[1] == 42, "failed key 1");
125 UCX_TEST_ASSERT(td[2] == 70, "failed key 2");
126 UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
127 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
128
129 UCX_TEST_ASSERT(map->count == 3, "expected 3 remaining values");
130 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0")==NULL, "element not removed");
131 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key1")!=NULL, "element removed");
132 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key2")==NULL, "element not removed");
133 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KeY3")!=NULL, "element removed");
134 UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KEY4")!=NULL, "element removed");
135
136 UCX_TEST_ASSERT(ucx_map_cstr_remove(map, "Key2") == NULL,
137 "subsequent remove call shall return NULL");
138
98 UCX_TEST_END 139 UCX_TEST_END
99 ucx_map_free(map); 140 ucx_map_free(map);
100 } 141 }
101 142
102 UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) { 143 UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) {

mercurial