283 UCX_TEST_END |
283 UCX_TEST_END |
284 |
284 |
285 ucx_map_free(map); |
285 ucx_map_free(map); |
286 ucx_map_free(clone); |
286 ucx_map_free(clone); |
287 } |
287 } |
|
288 |
|
289 UCX_TEST_IMPLEMENT(test_ucx_map_rehash) { |
|
290 UcxMap *map = ucx_map_new(4); |
|
291 |
|
292 char keys[10][5]; |
|
293 char values[10][7]; |
|
294 for (int i = 0 ; i < 10 ; i++) { |
|
295 strcpy(keys[i], "key"); |
|
296 keys[i][3] = 48+i; keys[i][4] = 0; |
|
297 strcpy(values[i], "value"); |
|
298 values[i][5] = 48+i; values[i][6] = 0; |
|
299 |
|
300 ucx_map_cstr_put(map, keys[i], values[i]); |
|
301 } |
|
302 |
|
303 map = ucx_map_rehash(map); |
|
304 |
|
305 UCX_TEST_BEGIN |
|
306 UCX_TEST_ASSERT(map->size == 25, "new capacity shall be 2.5 * count"); |
|
307 UCX_TEST_ASSERT(map->count == 10, "new map element count incorrect"); |
|
308 for (int i = 0 ; i < 10 ; i++) { |
|
309 char *value = ucx_map_cstr_get(map, keys[i]); |
|
310 UCX_TEST_ASSERT(value != NULL, "new map is missing old keys"); |
|
311 UCX_TEST_ASSERT(strncmp(value, values[i], 6) == 0, |
|
312 "new map contains incorrect values"); |
|
313 } |
|
314 UcxMap *samemap = ucx_map_rehash(map); |
|
315 UCX_TEST_ASSERT(samemap == map, |
|
316 "subsequent rehashing call shall do nothing"); |
|
317 UCX_TEST_ASSERT(samemap->size == 25, |
|
318 "subsequent rehashing call shall not change size"); |
|
319 UCX_TEST_END |
|
320 |
|
321 ucx_map_free(map); |
|
322 } |