test/map_tests.c

changeset 390
d345541018fa
parent 389
92e482410453
child 391
f094a53c1178
     1.1 --- a/test/map_tests.c	Mon Dec 30 09:54:10 2019 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,431 +0,0 @@
     1.4 -/*
     1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 - *
     1.7 - * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
     1.8 - *
     1.9 - * Redistribution and use in source and binary forms, with or without
    1.10 - * modification, are permitted provided that the following conditions are met:
    1.11 - *
    1.12 - *   1. Redistributions of source code must retain the above copyright
    1.13 - *      notice, this list of conditions and the following disclaimer.
    1.14 - *
    1.15 - *   2. Redistributions in binary form must reproduce the above copyright
    1.16 - *      notice, this list of conditions and the following disclaimer in the
    1.17 - *      documentation and/or other materials provided with the distribution.
    1.18 - *
    1.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    1.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.29 - * POSSIBILITY OF SUCH DAMAGE.
    1.30 - */
    1.31 -
    1.32 -#include "map_tests.h"
    1.33 -#include <ucx/utils.h>
    1.34 -
    1.35 -UCX_TEST(test_ucx_map_new) {
    1.36 -    UcxMap *map = ucx_map_new(16);
    1.37 -    UCX_TEST_BEGIN
    1.38 -    UCX_TEST_ASSERT(map->size == 16, "wrong size");
    1.39 -    UCX_TEST_ASSERT(map->map != NULL, "failed");
    1.40 -    
    1.41 -    UCX_TEST_END
    1.42 -    ucx_map_free(map);
    1.43 -}
    1.44 -
    1.45 -UCX_TEST(test_ucx_key) {
    1.46 -    UcxKey key = ucx_key("This is a text.", 15);
    1.47 -    UCX_TEST_BEGIN
    1.48 -    UCX_TEST_ASSERT(strncmp((const char*)key.data, "This is a text.", 15) == 0,
    1.49 -            "failed");
    1.50 -    UCX_TEST_ASSERT(key.len == 15, "failed");
    1.51 -    UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed");
    1.52 -    
    1.53 -    UCX_TEST_END
    1.54 -}
    1.55 -
    1.56 -UCX_TEST(test_ucx_map_put) {
    1.57 -    
    1.58 -    UcxMap *map = ucx_map_new(4);
    1.59 -    
    1.60 -    int td[5];
    1.61 -    td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
    1.62 -
    1.63 -    UCX_TEST_BEGIN
    1.64 -    ucx_map_cstr_put(map, "Key2", &td[2]); /* 3.2 */
    1.65 -    ucx_map_cstr_put(map, "Key0", &td[0]); /* 0.0 */
    1.66 -    ucx_map_cstr_put(map, "Key1", &td[1]); /* 3.0 */
    1.67 -    ucx_map_cstr_put(map, "KeY3", &td[3]); /* 3.1 */
    1.68 -    ucx_map_cstr_put(map, "KEY4", &td[4]); /* 1.0 */
    1.69 -    
    1.70 -    UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0");
    1.71 -    UCX_TEST_ASSERT(*((int*)map->map[1]->data) == td[4], "failed KEY4");
    1.72 -    UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1");
    1.73 -    
    1.74 -    UCX_TEST_ASSERT(map->map[3]->next != NULL, "no list at slot 3");
    1.75 -    UCX_TEST_ASSERT(map->map[3]->next->next != NULL, "list corrupt at slot 3");
    1.76 -    UCX_TEST_ASSERT(*((int*)map->map[3]->next->data) == td[3],
    1.77 -            "failed KeY3")
    1.78 -    UCX_TEST_ASSERT(*((int*)map->map[3]->next->next->data) == td[2],
    1.79 -            "failed KeY2");
    1.80 -
    1.81 -    UCX_TEST_ASSERT(map->map[0]->next == NULL, "slot 0 not terminated");
    1.82 -    UCX_TEST_ASSERT(map->map[1]->next == NULL, "slot 1 not terminated");
    1.83 -    UCX_TEST_ASSERT(map->map[2] == NULL, "slot 2 not empty");
    1.84 -    UCX_TEST_ASSERT(map->map[3]->next->next->next == NULL,
    1.85 -            "slot 3 not terminated")
    1.86 -
    1.87 -    ucx_map_cstr_put(map, "KeY3", &td[4]); /* replace 3.1 */
    1.88 -    
    1.89 -    UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1],
    1.90 -            "overwrite failed")
    1.91 -    UCX_TEST_ASSERT(*((int*)map->map[3]->next->data) == td[4],
    1.92 -            "overwrite failed");
    1.93 -    UCX_TEST_ASSERT(*((int*)map->map[3]->next->next->data) == td[2], 
    1.94 -            "overwrite failed")
    1.95 -    UCX_TEST_ASSERT(map->map[3]->next->next->next == NULL, "overwrite failed");
    1.96 -    
    1.97 -    UCX_TEST_END
    1.98 -    ucx_map_free(map);
    1.99 -}
   1.100 -
   1.101 -UCX_TEST(test_ucx_map_get) {
   1.102 -    UcxMap *map = ucx_map_new(4);
   1.103 -
   1.104 -    int td[5];
   1.105 -    td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
   1.106 -
   1.107 -    ucx_map_cstr_put(map, "Key2", &td[2]);
   1.108 -    ucx_map_cstr_put(map, "Key0", &td[0]);
   1.109 -    ucx_map_cstr_put(map, "Key1", &td[1]);
   1.110 -    ucx_map_cstr_put(map, "KeY3", &td[3]);
   1.111 -    ucx_map_cstr_put(map, "KEY4", &td[4]);
   1.112 -    UCX_TEST_BEGIN
   1.113 -
   1.114 -    td[0] = *((int*)ucx_map_cstr_get(map, "Key0"));
   1.115 -    td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
   1.116 -    td[2] = *((int*)ucx_map_cstr_get(map, "Key2"));
   1.117 -    td[3] = *((int*)ucx_map_cstr_get(map, "KeY3"));
   1.118 -    td[4] = *((int*)ucx_map_cstr_get(map, "KEY4"));
   1.119 -    UCX_TEST_ASSERT(td[0] == 10, "failed key 0");
   1.120 -    UCX_TEST_ASSERT(td[1] == 42, "failed key 1");
   1.121 -    UCX_TEST_ASSERT(td[2] == 70, "failed key 2");
   1.122 -    UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
   1.123 -    UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
   1.124 -
   1.125 -    UCX_TEST_ASSERT(map->count == 5, "expected 5 remaining values");
   1.126 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0") != NULL, "element removed");
   1.127 -
   1.128 -    UCX_TEST_END
   1.129 -    ucx_map_free(map);
   1.130 -}
   1.131 -
   1.132 -UCX_TEST(test_ucx_map_remove) {
   1.133 -    UcxMap *map = ucx_map_new(4);
   1.134 -
   1.135 -    int td[5];
   1.136 -    td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
   1.137 -
   1.138 -    ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */
   1.139 -    ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
   1.140 -    ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
   1.141 -    ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */
   1.142 -    ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */
   1.143 -    UCX_TEST_BEGIN
   1.144 -
   1.145 -    td[0] = *((int*)ucx_map_cstr_remove(map, "Key0"));
   1.146 -    td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
   1.147 -    td[2] = *((int*)ucx_map_cstr_remove(map, "Key2"));
   1.148 -    td[3] = *((int*)ucx_map_cstr_get(map, "KeY3"));
   1.149 -    td[4] = *((int*)ucx_map_cstr_get(map, "KEY4"));
   1.150 -    UCX_TEST_ASSERT(td[0] == 10, "failed key 0");
   1.151 -    UCX_TEST_ASSERT(td[1] == 42, "failed key 1");
   1.152 -    UCX_TEST_ASSERT(td[2] == 70, "failed key 2");
   1.153 -    UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
   1.154 -    UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
   1.155 -
   1.156 -    UCX_TEST_ASSERT(map->count == 3, "expected 3 remaining values");
   1.157 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0")==NULL, "element not removed");
   1.158 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key1")!=NULL, "element removed");
   1.159 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key2")==NULL, "element not removed");
   1.160 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KeY3")!=NULL, "element removed");
   1.161 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KEY4")!=NULL, "element removed");
   1.162 -
   1.163 -    UCX_TEST_ASSERT(ucx_map_cstr_remove(map, "Key2") == NULL,
   1.164 -            "subsequent remove call shall return NULL");
   1.165 -
   1.166 -    UCX_TEST_END
   1.167 -    ucx_map_free(map);
   1.168 -}
   1.169 -
   1.170 -UCX_TEST(test_ucx_map_clear) {
   1.171 -    UcxMap *map = ucx_map_new(4);
   1.172 -
   1.173 -    int value = 42;
   1.174 -
   1.175 -    ucx_map_cstr_put(map, "Key0", &value);
   1.176 -    ucx_map_cstr_put(map, "Key1", &value);
   1.177 -    ucx_map_cstr_put(map, "Key2", &value);
   1.178 -    ucx_map_cstr_put(map, "Key3", &value);
   1.179 -    ucx_map_cstr_put(map, "Key4", &value);
   1.180 -    ucx_map_cstr_put(map, "Key5", &value);
   1.181 -    ucx_map_cstr_put(map, "Key6", &value);
   1.182 -    UCX_TEST_BEGIN
   1.183 -        
   1.184 -    ucx_map_clear(map);
   1.185 -
   1.186 -    UCX_TEST_ASSERT(map->count == 0, "map has not been cleared");
   1.187 -    UCX_TEST_ASSERT(map->size == 4, "map size has changed unexpectedly");
   1.188 -
   1.189 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0")==NULL, "element not removed");
   1.190 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key1")==NULL, "element not removed");
   1.191 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key2")==NULL, "element not removed");
   1.192 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key3")==NULL, "element not removed");
   1.193 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key4")==NULL, "element not removed");
   1.194 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key5")==NULL, "element not removed");
   1.195 -    UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key6")==NULL, "element not removed");
   1.196 -
   1.197 -    UCX_TEST_END
   1.198 -    ucx_map_free(map);
   1.199 -}
   1.200 -
   1.201 -UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, UcxMap *map) {
   1.202 -    int v1 = 10;
   1.203 -    int v2 = 15;
   1.204 -    int v3 = 7;
   1.205 -    int v4 = 9;
   1.206 -
   1.207 -    ucx_map_cstr_put(map, "v1", &v1);
   1.208 -    ucx_map_cstr_put(map, "v2", &v2);
   1.209 -    ucx_map_cstr_put(map, "v3", &v3);
   1.210 -    ucx_map_cstr_put(map, "v4", &v4);
   1.211 -
   1.212 -    UcxMapIterator i = ucx_map_iterator(map);
   1.213 -    int check = 0;
   1.214 -    int hit = 0;
   1.215 -
   1.216 -    void* v;
   1.217 -    UCX_MAP_FOREACH(key, v, i) {
   1.218 -        check += *((int*)v);
   1.219 -        hit++;
   1.220 -    }
   1.221 -
   1.222 -    UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits");
   1.223 -    UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result");
   1.224 -}
   1.225 -
   1.226 -UCX_TEST(test_ucx_map_iterator) {
   1.227 -    UcxMap *map = ucx_map_new(16);
   1.228 -    UCX_TEST_BEGIN
   1.229 -    UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
   1.230 -    UCX_TEST_END
   1.231 -    ucx_map_free(map);
   1.232 -}
   1.233 -
   1.234 -UCX_TEST(test_ucx_map_iterator_chain) {
   1.235 -    UcxMap *map = ucx_map_new(1);
   1.236 -    UCX_TEST_BEGIN
   1.237 -    UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
   1.238 -    UCX_TEST_END
   1.239 -    ucx_map_free(map);
   1.240 -}
   1.241 -
   1.242 -UCX_TEST(test_ucx_map_clone) {
   1.243 -    UcxMap *map = ucx_map_new(4);
   1.244 -    
   1.245 -    ucx_map_cstr_put(map, "key1", (void*)"value1");
   1.246 -    ucx_map_cstr_put(map, "key2", (void*)"value2");
   1.247 -    ucx_map_cstr_put(map, "key3", (void*)"value3");
   1.248 -    
   1.249 -    UcxMap *clone = ucx_map_clone(map, NULL, NULL);
   1.250 -    
   1.251 -    const char *v1 = (const char *) ucx_map_cstr_get(map, "key1");
   1.252 -    const char *v2 = (const char *) ucx_map_cstr_get(map, "key2");
   1.253 -    const char *v3 = (const char *) ucx_map_cstr_get(map, "key3");
   1.254 -    
   1.255 -    UCX_TEST_BEGIN
   1.256 -    
   1.257 -    UCX_TEST_ASSERT(v1 != NULL, "failed key 1");
   1.258 -    UCX_TEST_ASSERT(v2 != NULL, "failed key 2");
   1.259 -    UCX_TEST_ASSERT(v3 != NULL, "failed key 3");
   1.260 -    
   1.261 -    const char *c1 = (const char *) ucx_map_cstr_get(clone, "key1");
   1.262 -    const char *c2 = (const char *) ucx_map_cstr_get(clone, "key2");
   1.263 -    const char *c3 = (const char *) ucx_map_cstr_get(clone, "key3");
   1.264 -    
   1.265 -    UCX_TEST_ASSERT(c1 != NULL, "failed key 1 (clone)");
   1.266 -    UCX_TEST_ASSERT(c2 != NULL, "failed key 2 (clone)");
   1.267 -    UCX_TEST_ASSERT(c3 != NULL, "failed key 3 (clone)");
   1.268 -    
   1.269 -    UCX_TEST_ASSERT(strcmp(c1, v1) == 0, "value error for key1");
   1.270 -    UCX_TEST_ASSERT(strcmp(c2, v2) == 0, "value error for key2");
   1.271 -    UCX_TEST_ASSERT(strcmp(c3, v3) == 0, "value error for key3");
   1.272 -    
   1.273 -    UCX_TEST_END
   1.274 -    
   1.275 -    ucx_map_free(map);
   1.276 -    ucx_map_free(clone);
   1.277 -}
   1.278 -
   1.279 -UCX_TEST(test_ucx_map_rehash) {
   1.280 -    UcxMap *map = ucx_map_new(4);
   1.281 -
   1.282 -    char keys[10][5];
   1.283 -    char values[10][7];
   1.284 -    for (int i = 0 ; i < 10 ; i++) {
   1.285 -        strcpy(keys[i], "key");
   1.286 -        keys[i][3] = 48+i; keys[i][4] = 0;
   1.287 -        strcpy(values[i], "value");
   1.288 -        values[i][5] = 48+i; values[i][6] = 0;
   1.289 -
   1.290 -        ucx_map_cstr_put(map, keys[i], values[i]);
   1.291 -    }
   1.292 -
   1.293 -    ucx_map_rehash(map);
   1.294 -
   1.295 -    UCX_TEST_BEGIN
   1.296 -    UCX_TEST_ASSERT(map->size == 25, "new capacity shall be 2.5 * count");
   1.297 -    UCX_TEST_ASSERT(map->count == 10, "new map element count incorrect");
   1.298 -    for (int i = 0 ; i < 10 ; i++) {
   1.299 -        const char *value = (const char *) ucx_map_cstr_get(map, keys[i]);
   1.300 -        UCX_TEST_ASSERT(value != NULL, "new map is missing old keys");
   1.301 -        UCX_TEST_ASSERT(strncmp(value, values[i], 6) == 0,
   1.302 -                "new map contains incorrect values");
   1.303 -    }
   1.304 -    ucx_map_rehash(map);
   1.305 -    UCX_TEST_ASSERT(map->size == 25,
   1.306 -            "subsequent rehashing call shall not change size");
   1.307 -    UCX_TEST_END
   1.308 -
   1.309 -    ucx_map_free(map);
   1.310 -}
   1.311 -
   1.312 -UCX_TEST(test_ucx_map_union) {
   1.313 -    int td[5];
   1.314 -    size_t intlen = sizeof(int);
   1.315 -    td[0] = 10; td[1] = 42; td[2] = 47; td[3] = 1337; td[4] = 9000;
   1.316 -
   1.317 -    UcxMap *first = ucx_map_new(4);
   1.318 -    UcxMap *second = ucx_map_new(4);
   1.319 -
   1.320 -    ucx_map_cstr_put(first, "key0", &td[0]);
   1.321 -    ucx_map_cstr_put(first, "key1", &td[1]);
   1.322 -    ucx_map_cstr_put(second, "key2", &td[2]);
   1.323 -    ucx_map_cstr_put(second, "key0", &td[3]);
   1.324 -    ucx_map_cstr_put(second, "key3", &td[4]);
   1.325 -
   1.326 -    UcxMap *result = ucx_map_union(first, second, ucx_memcpy, &intlen);
   1.327 -
   1.328 -    UCX_TEST_BEGIN
   1.329 -
   1.330 -    int* r;
   1.331 -    UCX_TEST_ASSERT(result->count == 4,
   1.332 -            "result has incorrect number of elements");
   1.333 -
   1.334 -    r = (int*)ucx_map_cstr_get(result, "key0");
   1.335 -    UCX_TEST_ASSERT(!!r, "key0 is not present");
   1.336 -    UCX_TEST_ASSERT(*r == td[3], "key0 has not been overwritten");
   1.337 -    r = (int*)ucx_map_cstr_get(result, "key1");
   1.338 -    UCX_TEST_ASSERT(!!r, "key1 is not present");
   1.339 -    UCX_TEST_ASSERT(*r == td[1], "key1 contains wrong data");
   1.340 -    r = (int*)ucx_map_cstr_get(result, "key2");
   1.341 -    UCX_TEST_ASSERT(!!r, "key2 is not present");
   1.342 -    UCX_TEST_ASSERT(*r == td[2], "key2 contains wrong data");
   1.343 -    r = (int*)ucx_map_cstr_get(result, "key3");
   1.344 -    UCX_TEST_ASSERT(!!r, "key3 is not present");
   1.345 -    UCX_TEST_ASSERT(*r == td[4], "key3 contains wrong data");
   1.346 -
   1.347 -    UCX_TEST_END
   1.348 -
   1.349 -    ucx_map_free_content(result, NULL);
   1.350 -    ucx_map_free(result);
   1.351 -    ucx_map_free(second);
   1.352 -    ucx_map_free(first);
   1.353 -}
   1.354 -
   1.355 -UCX_TEST(test_ucx_map_intersection) {
   1.356 -        int td[5];
   1.357 -        size_t intlen = sizeof(int);
   1.358 -        td[0] = 10; td[1] = 42; td[2] = 47; td[3] = 1337; td[4] = 9000;
   1.359 -
   1.360 -        UcxMap *first = ucx_map_new(4);
   1.361 -        UcxMap *second = ucx_map_new(4);
   1.362 -
   1.363 -        ucx_map_cstr_put(first, "key0", &td[0]);
   1.364 -        ucx_map_cstr_put(first, "key1", &td[1]);
   1.365 -        ucx_map_cstr_put(first, "key4", &td[3]);
   1.366 -        ucx_map_cstr_put(second, "key2", &td[2]);
   1.367 -        ucx_map_cstr_put(second, "key0", &td[3]);
   1.368 -        ucx_map_cstr_put(second, "key3", &td[4]);
   1.369 -        ucx_map_cstr_put(second, "key4", &td[4]);
   1.370 -
   1.371 -        UcxMap *result = ucx_map_intersection(first, second,
   1.372 -                ucx_memcpy, &intlen);
   1.373 -
   1.374 -        UCX_TEST_BEGIN
   1.375 -
   1.376 -        int* r;
   1.377 -        UCX_TEST_ASSERT(result->count == 2,
   1.378 -                "result has incorrect number of elements");
   1.379 -
   1.380 -        r = (int*)ucx_map_cstr_get(result, "key0");
   1.381 -        UCX_TEST_ASSERT(!!r, "key0 is not present");
   1.382 -        UCX_TEST_ASSERT(*r == td[0], "key0 has not original data");
   1.383 -        r = (int*)ucx_map_cstr_get(result, "key4");
   1.384 -        UCX_TEST_ASSERT(!!r, "key4 is not present");
   1.385 -        UCX_TEST_ASSERT(*r == td[3], "key4 has not original data");
   1.386 -
   1.387 -        UCX_TEST_END
   1.388 -
   1.389 -        ucx_map_free_content(result, NULL);
   1.390 -        ucx_map_free(result);
   1.391 -        ucx_map_free(second);
   1.392 -        ucx_map_free(first);
   1.393 -}
   1.394 -
   1.395 -
   1.396 -UCX_TEST(test_ucx_map_difference) {
   1.397 -        int td[5];
   1.398 -        size_t intlen = sizeof(int);
   1.399 -        td[0] = 10; td[1] = 42; td[2] = 47; td[3] = 1337; td[4] = 9000;
   1.400 -
   1.401 -        UcxMap *first = ucx_map_new(4);
   1.402 -        UcxMap *second = ucx_map_new(4);
   1.403 -
   1.404 -        ucx_map_cstr_put(first, "key0", &td[0]);
   1.405 -        ucx_map_cstr_put(first, "key1", &td[1]);
   1.406 -        ucx_map_cstr_put(first, "key2", &td[2]);
   1.407 -        ucx_map_cstr_put(first, "key4", &td[3]);
   1.408 -        ucx_map_cstr_put(second, "key0", &td[3]);
   1.409 -        ucx_map_cstr_put(second, "key3", &td[4]);
   1.410 -        ucx_map_cstr_put(second, "key4", &td[4]);
   1.411 -
   1.412 -        UcxMap *result = ucx_map_difference(first, second, ucx_memcpy, &intlen);
   1.413 -
   1.414 -        UCX_TEST_BEGIN
   1.415 -
   1.416 -        int* r;
   1.417 -        UCX_TEST_ASSERT(result->count == 2,
   1.418 -                "result has incorrect number of elements");
   1.419 -
   1.420 -        r = (int*)ucx_map_cstr_get(result, "key1");
   1.421 -        UCX_TEST_ASSERT(!!r, "key1 is not present");
   1.422 -        UCX_TEST_ASSERT(*r == td[1], "key1 has incorrect data");
   1.423 -        r = (int*)ucx_map_cstr_get(result, "key2");
   1.424 -        UCX_TEST_ASSERT(!!r, "key2 is not present");
   1.425 -        UCX_TEST_ASSERT(*r == td[2], "key2 has incorrect data");
   1.426 -
   1.427 -        UCX_TEST_END
   1.428 -
   1.429 -        ucx_map_free_content(result, NULL);
   1.430 -        ucx_map_free(result);
   1.431 -        ucx_map_free(second);
   1.432 -        ucx_map_free(first);
   1.433 -}
   1.434 -

mercurial