test/map_tests.c

changeset 40
583718dd4cf3
parent 34
0dcd2ca2a223
child 41
7f90a03e186e
equal deleted inserted replaced
39:bf8ab7bb74ff 40:583718dd4cf3
5 #include "map_tests.h" 5 #include "map_tests.h"
6 6
7 UCX_TEST_IMPLEMENT(test_ucx_map_new) { 7 UCX_TEST_IMPLEMENT(test_ucx_map_new) {
8 UcxMap *map = ucx_map_new(16); 8 UcxMap *map = ucx_map_new(16);
9 UCX_TEST_BEGIN 9 UCX_TEST_BEGIN
10 UCX_TEST_ASSERT(map->size == 16, "wrong size") 10 UCX_TEST_ASSERT(map->size == 16, "wrong size");
11 UCX_TEST_ASSERT(map->map != NULL, "failed") 11 UCX_TEST_ASSERT(map->map != NULL, "failed");
12 12
13 UCX_TEST_END 13 UCX_TEST_END
14 ucx_map_free(map); 14 ucx_map_free(map);
15 } 15 }
16 16
17 UCX_TEST_IMPLEMENT(test_ucx_key) { 17 UCX_TEST_IMPLEMENT(test_ucx_key) {
18 UcxKey key = ucx_key("This is a text.", 15); 18 UcxKey key = ucx_key("This is a text.", 15);
19 UCX_TEST_BEGIN 19 UCX_TEST_BEGIN
20 UCX_TEST_ASSERT(strncmp(key.data, "This is a text.", 15) == 0, "failed") 20 UCX_TEST_ASSERT(strncmp(key.data, "This is a text.", 15) == 0, "failed");
21 UCX_TEST_ASSERT(key.len == 15, "failed") 21 UCX_TEST_ASSERT(key.len == 15, "failed");
22 UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed") 22 UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed");
23 23
24 UCX_TEST_END 24 UCX_TEST_END
25 } 25 }
26 26
27 UCX_TEST_IMPLEMENT(test_ucx_map_put) { 27 UCX_TEST_IMPLEMENT(test_ucx_map_put) {
36 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */ 36 ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
37 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */ 37 ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
38 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */ 38 ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */
39 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */ 39 ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */
40 40
41 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0") 41 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[0], "failed Key0");
42 UCX_TEST_ASSERT(map->map[0]->next != NULL, "no list at slot 0") 42 UCX_TEST_ASSERT(map->map[0]->next != NULL, "no list at slot 0");
43 UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], "failed Key2") 43 UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], "failed Key2");
44 UCX_TEST_ASSERT(map->map[0]->next->next != NULL, "list corrupt at slot 0") 44 UCX_TEST_ASSERT(map->map[0]->next->next != NULL, "list corrupt at slot 0");
45 UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4], 45 UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4],
46 "failed Key4") 46 "failed Key4")
47 UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, 47 UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL,
48 "slot 0 not terminated") 48 "slot 0 not terminated")
49 49
50 UCX_TEST_ASSERT(map->map[1] == NULL, "slot 1 not terminated") 50 UCX_TEST_ASSERT(map->map[1] == NULL, "slot 1 not terminated");
51 51
52 UCX_TEST_ASSERT(*((int*)map->map[2]->data) == td[3], "failed KeY3") 52 UCX_TEST_ASSERT(*((int*)map->map[2]->data) == td[3], "failed KeY3");
53 UCX_TEST_ASSERT(map->map[2]->next == NULL, "slot 2 not terminated") 53 UCX_TEST_ASSERT(map->map[2]->next == NULL, "slot 2 not terminated");
54 54
55 UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1") 55 UCX_TEST_ASSERT(*((int*)map->map[3]->data) == td[1], "failed Key1");
56 56
57 ucx_map_cstr_put(map, "Key0", &td[3]); /* 0 */ 57 ucx_map_cstr_put(map, "Key0", &td[3]); /* 0 */
58 58
59 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[3], "overwrite failed") 59 UCX_TEST_ASSERT(*((int*)map->map[0]->data) == td[3], "overwrite failed");
60 UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2], 60 UCX_TEST_ASSERT(*((int*)map->map[0]->next->data) == td[2],
61 "overwrite failed") 61 "overwrite failed")
62 UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4], 62 UCX_TEST_ASSERT(*((int*)map->map[0]->next->next->data) == td[4],
63 "overwrite failed") 63 "overwrite failed")
64 UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, "overwrite failed") 64 UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, "overwrite failed");
65 65
66 UCX_TEST_END 66 UCX_TEST_END
67 ucx_map_free(map); 67 ucx_map_free(map);
68 } 68 }
69 69
83 td[0] = *((int*)ucx_map_cstr_get(map, "Key0")); 83 td[0] = *((int*)ucx_map_cstr_get(map, "Key0"));
84 td[1] = *((int*)ucx_map_cstr_get(map, "Key1")); 84 td[1] = *((int*)ucx_map_cstr_get(map, "Key1"));
85 td[2] = *((int*)ucx_map_cstr_get(map, "Key2")); 85 td[2] = *((int*)ucx_map_cstr_get(map, "Key2"));
86 td[3] = *((int*)ucx_map_cstr_get(map, "KeY3")); 86 td[3] = *((int*)ucx_map_cstr_get(map, "KeY3"));
87 td[4] = *((int*)ucx_map_cstr_get(map, "KEY4")); 87 td[4] = *((int*)ucx_map_cstr_get(map, "KEY4"));
88 UCX_TEST_ASSERT(td[0] == 10, "failed key 0") 88 UCX_TEST_ASSERT(td[0] == 10, "failed key 0");
89 UCX_TEST_ASSERT(td[1] == 42, "failed key 1") 89 UCX_TEST_ASSERT(td[1] == 42, "failed key 1");
90 UCX_TEST_ASSERT(td[2] == 70, "failed key 2") 90 UCX_TEST_ASSERT(td[2] == 70, "failed key 2");
91 UCX_TEST_ASSERT(td[3] == 11200, "failed key 3") 91 UCX_TEST_ASSERT(td[3] == 11200, "failed key 3");
92 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4") 92 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4");
93 93
94 UCX_TEST_END 94 UCX_TEST_END
95 ucx_map_free(map); 95 ucx_map_free(map);
96 } 96 }
97 97

mercurial