test/map_tests.c

changeset 31
91ac86557290
parent 29
bce0d7f2912b
child 32
c7af4ec56e19
equal deleted inserted replaced
30:23bb65cbf7a4 31:91ac86557290
69 } 69 }
70 70
71 UCX_TEST_BEGIN(test_ucx_map_get) { 71 UCX_TEST_BEGIN(test_ucx_map_get) {
72 UCX_TEST_END 72 UCX_TEST_END
73 } 73 }
74
75 UCX_TEST_BEGIN(test_ucx_map_iterator) {
76 UcxMap *map = ucx_map_new(16);
77
78 int v1 = 10;
79 int v2 = 15;
80 int v3 = 7;
81 int v4 = 9;
82
83 ucx_map_cstr_put(map, "v1", &v1);
84 ucx_map_cstr_put(map, "v2", &v2);
85 ucx_map_cstr_put(map, "v3", &v3);
86 ucx_map_cstr_put(map, "v4", &v4);
87
88 UcxMapIterator i = ucx_map_iterator(map);
89 int check = 0;
90 int hit = 0;
91
92 UCX_MAP_FOREACH(int*, v, map, i) {
93 check += *v;
94 hit++;
95 }
96
97 UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits");
98 UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result");
99
100 ucx_map_free(map);
101
102 map = ucx_map_new(1);
103 ucx_map_cstr_put(map, "v1", &v1);
104 ucx_map_cstr_put(map, "v2", &v2);
105 ucx_map_cstr_put(map, "v3", &v3);
106 ucx_map_cstr_put(map, "v4", &v4);
107
108 i = ucx_map_iterator(map);
109 check = 0;
110 hit = 0;
111
112 UCX_MAP_FOREACH(int*, v, map, i) {
113 check += *v;
114 hit++;
115 }
116
117 UCX_TEST_ASSERT(hit == 4, "test2: wrong number of hits");
118 UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test2: wrong result");
119
120
121 ucx_map_free(map);
122
123 UCX_TEST_END
124 }

mercurial