test/map_tests.c

changeset 134
4d320dc3a7af
parent 112
6384016df2a3
child 152
3238f65db163
equal deleted inserted replaced
133:0a70e0d36949 134:4d320dc3a7af
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "map_tests.h" 29 #include "map_tests.h"
30 30
31 UCX_TEST_IMPLEMENT(test_ucx_map_new) { 31 UCX_TEST(test_ucx_map_new) {
32 UcxMap *map = ucx_map_new(16); 32 UcxMap *map = ucx_map_new(16);
33 UCX_TEST_BEGIN 33 UCX_TEST_BEGIN
34 UCX_TEST_ASSERT(map->size == 16, "wrong size"); 34 UCX_TEST_ASSERT(map->size == 16, "wrong size");
35 UCX_TEST_ASSERT(map->map != NULL, "failed"); 35 UCX_TEST_ASSERT(map->map != NULL, "failed");
36 36
37 UCX_TEST_END 37 UCX_TEST_END
38 ucx_map_free(map); 38 ucx_map_free(map);
39 } 39 }
40 40
41 UCX_TEST_IMPLEMENT(test_ucx_key) { 41 UCX_TEST(test_ucx_key) {
42 UcxKey key = ucx_key((void*)"This is a text.", 15); 42 UcxKey key = ucx_key((void*)"This is a text.", 15);
43 UCX_TEST_BEGIN 43 UCX_TEST_BEGIN
44 UCX_TEST_ASSERT(strncmp((const char*)key.data, "This is a text.", 15) == 0, 44 UCX_TEST_ASSERT(strncmp((const char*)key.data, "This is a text.", 15) == 0,
45 "failed"); 45 "failed");
46 UCX_TEST_ASSERT(key.len == 15, "failed"); 46 UCX_TEST_ASSERT(key.len == 15, "failed");
47 UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed"); 47 UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed");
48 48
49 UCX_TEST_END 49 UCX_TEST_END
50 } 50 }
51 51
52 UCX_TEST_IMPLEMENT(test_ucx_map_put) { 52 UCX_TEST(test_ucx_map_put) {
53 53
54 UcxMap *map = ucx_map_new(4); 54 UcxMap *map = ucx_map_new(4);
55 55
56 int td[5]; 56 int td[5];
57 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; 57 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
92 92
93 UCX_TEST_END 93 UCX_TEST_END
94 ucx_map_free(map); 94 ucx_map_free(map);
95 } 95 }
96 96
97 UCX_TEST_IMPLEMENT(test_ucx_map_get) { 97 UCX_TEST(test_ucx_map_get) {
98 UcxMap *map = ucx_map_new(4); 98 UcxMap *map = ucx_map_new(4);
99 99
100 int td[5]; 100 int td[5];
101 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; 101 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
102 102
123 123
124 UCX_TEST_END 124 UCX_TEST_END
125 ucx_map_free(map); 125 ucx_map_free(map);
126 } 126 }
127 127
128 UCX_TEST_IMPLEMENT(test_ucx_map_remove) { 128 UCX_TEST(test_ucx_map_remove) {
129 UcxMap *map = ucx_map_new(4); 129 UcxMap *map = ucx_map_new(4);
130 130
131 int td[5]; 131 int td[5];
132 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; 132 td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
133 133
186 186
187 UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits"); 187 UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits");
188 UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result"); 188 UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result");
189 } 189 }
190 190
191 UCX_TEST_IMPLEMENT(test_ucx_map_iterator) { 191 UCX_TEST(test_ucx_map_iterator) {
192 UcxMap *map = ucx_map_new(16); 192 UcxMap *map = ucx_map_new(16);
193 UCX_TEST_BEGIN 193 UCX_TEST_BEGIN
194 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) 194 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
195 UCX_TEST_END 195 UCX_TEST_END
196 ucx_map_free(map); 196 ucx_map_free(map);
197 } 197 }
198 198
199 UCX_TEST_IMPLEMENT(test_ucx_map_iterator_chain) { 199 UCX_TEST(test_ucx_map_iterator_chain) {
200 UcxMap *map = ucx_map_new(1); 200 UcxMap *map = ucx_map_new(1);
201 UCX_TEST_BEGIN 201 UCX_TEST_BEGIN
202 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) 202 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
203 UCX_TEST_END 203 UCX_TEST_END
204 ucx_map_free(map); 204 ucx_map_free(map);
205 } 205 }
206 206
207 UCX_TEST_IMPLEMENT(test_ucx_map_clone) { 207 UCX_TEST(test_ucx_map_clone) {
208 UcxMap *map = ucx_map_new(4); 208 UcxMap *map = ucx_map_new(4);
209 209
210 ucx_map_cstr_put(map, "key1", (void*)"value1"); 210 ucx_map_cstr_put(map, "key1", (void*)"value1");
211 ucx_map_cstr_put(map, "key2", (void*)"value2"); 211 ucx_map_cstr_put(map, "key2", (void*)"value2");
212 ucx_map_cstr_put(map, "key3", (void*)"value3"); 212 ucx_map_cstr_put(map, "key3", (void*)"value3");
239 239
240 ucx_map_free(map); 240 ucx_map_free(map);
241 ucx_map_free(clone); 241 ucx_map_free(clone);
242 } 242 }
243 243
244 UCX_TEST_IMPLEMENT(test_ucx_map_rehash) { 244 UCX_TEST(test_ucx_map_rehash) {
245 UcxMap *map = ucx_map_new(4); 245 UcxMap *map = ucx_map_new(4);
246 246
247 char keys[10][5]; 247 char keys[10][5];
248 char values[10][7]; 248 char values[10][7];
249 for (int i = 0 ; i < 10 ; i++) { 249 for (int i = 0 ; i < 10 ; i++) {

mercurial