1.1 --- a/test/map_tests.c Thu Dec 19 18:47:23 2019 +0100 1.2 +++ b/test/map_tests.c Thu Dec 19 19:58:41 2019 +0100 1.3 @@ -27,6 +27,7 @@ 1.4 */ 1.5 1.6 #include "map_tests.h" 1.7 +#include <ucx/utils.h> 1.8 1.9 UCX_TEST(test_ucx_map_new) { 1.10 UcxMap *map = ucx_map_new(16); 1.11 @@ -304,3 +305,127 @@ 1.12 1.13 ucx_map_free(map); 1.14 } 1.15 + 1.16 +UCX_TEST(test_ucx_map_union) { 1.17 + int td[5]; 1.18 + size_t intlen = sizeof(int); 1.19 + td[0] = 10; td[1] = 42; td[2] = 47; td[3] = 1337; td[4] = 9000; 1.20 + 1.21 + UcxMap *first = ucx_map_new(4); 1.22 + UcxMap *second = ucx_map_new(4); 1.23 + 1.24 + ucx_map_cstr_put(first, "key0", &td[0]); 1.25 + ucx_map_cstr_put(first, "key1", &td[1]); 1.26 + ucx_map_cstr_put(second, "key2", &td[2]); 1.27 + ucx_map_cstr_put(second, "key0", &td[3]); 1.28 + ucx_map_cstr_put(second, "key3", &td[4]); 1.29 + 1.30 + UcxMap *result = ucx_map_union(first, second, ucx_memcpy, &intlen); 1.31 + 1.32 + UCX_TEST_BEGIN 1.33 + 1.34 + int* r; 1.35 + UCX_TEST_ASSERT(result->count == 4, 1.36 + "result has incorrect number of elements"); 1.37 + 1.38 + r = (int*)ucx_map_cstr_get(result, "key0"); 1.39 + UCX_TEST_ASSERT(!!r, "key0 is not present"); 1.40 + UCX_TEST_ASSERT(*r == td[3], "key0 has not been overwritten"); 1.41 + r = (int*)ucx_map_cstr_get(result, "key1"); 1.42 + UCX_TEST_ASSERT(!!r, "key1 is not present"); 1.43 + UCX_TEST_ASSERT(*r == td[1], "key1 contains wrong data"); 1.44 + r = (int*)ucx_map_cstr_get(result, "key2"); 1.45 + UCX_TEST_ASSERT(!!r, "key2 is not present"); 1.46 + UCX_TEST_ASSERT(*r == td[2], "key2 contains wrong data"); 1.47 + r = (int*)ucx_map_cstr_get(result, "key3"); 1.48 + UCX_TEST_ASSERT(!!r, "key3 is not present"); 1.49 + UCX_TEST_ASSERT(*r == td[4], "key3 contains wrong data"); 1.50 + 1.51 + UCX_TEST_END 1.52 + 1.53 + ucx_map_free_content(result, NULL); 1.54 + ucx_map_free(result); 1.55 + ucx_map_free(second); 1.56 + ucx_map_free(first); 1.57 +} 1.58 + 1.59 +UCX_TEST(test_ucx_map_intersection) { 1.60 + int td[5]; 1.61 + size_t intlen = sizeof(int); 1.62 + td[0] = 10; td[1] = 42; td[2] = 47; td[3] = 1337; td[4] = 9000; 1.63 + 1.64 + UcxMap *first = ucx_map_new(4); 1.65 + UcxMap *second = ucx_map_new(4); 1.66 + 1.67 + ucx_map_cstr_put(first, "key0", &td[0]); 1.68 + ucx_map_cstr_put(first, "key1", &td[1]); 1.69 + ucx_map_cstr_put(first, "key4", &td[3]); 1.70 + ucx_map_cstr_put(second, "key2", &td[2]); 1.71 + ucx_map_cstr_put(second, "key0", &td[3]); 1.72 + ucx_map_cstr_put(second, "key3", &td[4]); 1.73 + ucx_map_cstr_put(second, "key4", &td[4]); 1.74 + 1.75 + UcxMap *result = ucx_map_intersection(first, second, 1.76 + ucx_memcpy, &intlen); 1.77 + 1.78 + UCX_TEST_BEGIN 1.79 + 1.80 + int* r; 1.81 + UCX_TEST_ASSERT(result->count == 2, 1.82 + "result has incorrect number of elements"); 1.83 + 1.84 + r = (int*)ucx_map_cstr_get(result, "key0"); 1.85 + UCX_TEST_ASSERT(!!r, "key0 is not present"); 1.86 + UCX_TEST_ASSERT(*r == td[0], "key0 has not original data"); 1.87 + r = (int*)ucx_map_cstr_get(result, "key4"); 1.88 + UCX_TEST_ASSERT(!!r, "key4 is not present"); 1.89 + UCX_TEST_ASSERT(*r == td[3], "key4 has not original data"); 1.90 + 1.91 + UCX_TEST_END 1.92 + 1.93 + ucx_map_free_content(result, NULL); 1.94 + ucx_map_free(result); 1.95 + ucx_map_free(second); 1.96 + ucx_map_free(first); 1.97 +} 1.98 + 1.99 + 1.100 +UCX_TEST(test_ucx_map_difference) { 1.101 + int td[5]; 1.102 + size_t intlen = sizeof(int); 1.103 + td[0] = 10; td[1] = 42; td[2] = 47; td[3] = 1337; td[4] = 9000; 1.104 + 1.105 + UcxMap *first = ucx_map_new(4); 1.106 + UcxMap *second = ucx_map_new(4); 1.107 + 1.108 + ucx_map_cstr_put(first, "key0", &td[0]); 1.109 + ucx_map_cstr_put(first, "key1", &td[1]); 1.110 + ucx_map_cstr_put(first, "key2", &td[2]); 1.111 + ucx_map_cstr_put(first, "key4", &td[3]); 1.112 + ucx_map_cstr_put(second, "key0", &td[3]); 1.113 + ucx_map_cstr_put(second, "key3", &td[4]); 1.114 + ucx_map_cstr_put(second, "key4", &td[4]); 1.115 + 1.116 + UcxMap *result = ucx_map_difference(first, second, ucx_memcpy, &intlen); 1.117 + 1.118 + UCX_TEST_BEGIN 1.119 + 1.120 + int* r; 1.121 + UCX_TEST_ASSERT(result->count == 2, 1.122 + "result has incorrect number of elements"); 1.123 + 1.124 + r = (int*)ucx_map_cstr_get(result, "key1"); 1.125 + UCX_TEST_ASSERT(!!r, "key1 is not present"); 1.126 + UCX_TEST_ASSERT(*r == td[1], "key1 has incorrect data"); 1.127 + r = (int*)ucx_map_cstr_get(result, "key2"); 1.128 + UCX_TEST_ASSERT(!!r, "key2 is not present"); 1.129 + UCX_TEST_ASSERT(*r == td[2], "key2 has incorrect data"); 1.130 + 1.131 + UCX_TEST_END 1.132 + 1.133 + ucx_map_free_content(result, NULL); 1.134 + ucx_map_free(result); 1.135 + ucx_map_free(second); 1.136 + ucx_map_free(first); 1.137 +} 1.138 +