test/map_tests.c

changeset 51
1c78cd19fb6b
parent 48
621a4430c404
child 52
34f50d0bada4
     1.1 --- a/test/map_tests.c	Fri Oct 05 13:23:25 2012 +0200
     1.2 +++ b/test/map_tests.c	Fri Oct 05 14:06:40 2012 +0200
     1.3 @@ -285,3 +285,38 @@
     1.4      ucx_map_free(map);
     1.5      ucx_map_free(clone);
     1.6  }
     1.7 +
     1.8 +UCX_TEST_IMPLEMENT(test_ucx_map_rehash) {
     1.9 +    UcxMap *map = ucx_map_new(4);
    1.10 +
    1.11 +    char keys[10][5];
    1.12 +    char values[10][7];
    1.13 +    for (int i = 0 ; i < 10 ; i++) {
    1.14 +        strcpy(keys[i], "key");
    1.15 +        keys[i][3] = 48+i; keys[i][4] = 0;
    1.16 +        strcpy(values[i], "value");
    1.17 +        values[i][5] = 48+i; values[i][6] = 0;
    1.18 +
    1.19 +        ucx_map_cstr_put(map, keys[i], values[i]);
    1.20 +    }
    1.21 +
    1.22 +    map = ucx_map_rehash(map);
    1.23 +
    1.24 +    UCX_TEST_BEGIN
    1.25 +    UCX_TEST_ASSERT(map->size == 25, "new capacity shall be 2.5 * count");
    1.26 +    UCX_TEST_ASSERT(map->count == 10, "new map element count incorrect");
    1.27 +    for (int i = 0 ; i < 10 ; i++) {
    1.28 +        char *value = ucx_map_cstr_get(map, keys[i]);
    1.29 +        UCX_TEST_ASSERT(value != NULL, "new map is missing old keys");
    1.30 +        UCX_TEST_ASSERT(strncmp(value, values[i], 6) == 0,
    1.31 +                "new map contains incorrect values");
    1.32 +    }
    1.33 +    UcxMap *samemap = ucx_map_rehash(map);
    1.34 +    UCX_TEST_ASSERT(samemap == map,
    1.35 +            "subsequent rehashing call shall do nothing");
    1.36 +    UCX_TEST_ASSERT(samemap->size == 25,
    1.37 +            "subsequent rehashing call shall not change size");
    1.38 +    UCX_TEST_END
    1.39 +
    1.40 +    ucx_map_free(map);
    1.41 +}

mercurial