140 ucx_avl_free(tree2); |
140 ucx_avl_free(tree2); |
141 ucx_avl_free(tree3); |
141 ucx_avl_free(tree3); |
142 ucx_avl_free(tree4); |
142 ucx_avl_free(tree4); |
143 ucx_avl_free(tree5); |
143 ucx_avl_free(tree5); |
144 } |
144 } |
|
145 |
|
146 UCX_TEST(test_ucx_avl_remove) { |
|
147 UcxAVLTree *tree1 = ucx_avl_new(ucx_ptrcmp); |
|
148 UcxAVLTree *tree2 = ucx_avl_new(ucx_ptrcmp); |
|
149 UcxAVLTree *tree3 = ucx_avl_new(ucx_ptrcmp); |
|
150 UcxAVLTree *tree4 = ucx_avl_new(ucx_ptrcmp); |
|
151 |
|
152 char *data1 = (char*)"data1"; |
|
153 char *data2 = (char*)"data2"; |
|
154 char *data3 = (char*)"data3"; |
|
155 |
|
156 UCX_TEST_BEGIN |
|
157 ucx_avl_put(tree1, 2, (char*)data2); |
|
158 ucx_avl_put(tree1, 1, (char*)data1); |
|
159 ucx_avl_put(tree1, 3, (char*)data3); |
|
160 void *val = ucx_avl_remove(tree1, 3); |
|
161 |
|
162 UCX_TEST_ASSERT(check_tree(tree1->root), "check_tree failed (tree1)"); |
|
163 UCX_TEST_ASSERT(val == data3, "wrong return value (tree1)"); |
|
164 UCX_TEST_ASSERT(ucx_avl_get(tree1, 3) == NULL, "value not removed (tree1)"); |
|
165 |
|
166 for(int i=0;i<20;i++) { |
|
167 if(i==10) { |
|
168 ucx_avl_put(tree2, i, data3); |
|
169 } else if(i==15) { |
|
170 ucx_avl_put(tree2, i, data2); |
|
171 } else { |
|
172 ucx_avl_put(tree2, i, data1); |
|
173 } |
|
174 } |
|
175 |
|
176 UCX_TEST_ASSERT( |
|
177 ucx_avl_remove(tree2, 10) == data3, |
|
178 "wrong return value for key: 10 (tree2)"); |
|
179 UCX_TEST_ASSERT(check_tree(tree2->root), "check_tree failed (tree2)"); |
|
180 |
|
181 UCX_TEST_ASSERT( |
|
182 ucx_avl_remove(tree2, 15) == data2, |
|
183 "wrong return value for key: 15 (tree2)"); |
|
184 UCX_TEST_ASSERT(check_tree(tree2->root), "check_tree failed (tree2)"); |
|
185 |
|
186 for(int i=0;i<20;i++) { |
|
187 ucx_avl_remove(tree2, i); |
|
188 UCX_TEST_ASSERT(check_tree(tree2->root), "check_tree failed (tree2)"); |
|
189 } |
|
190 |
|
191 for(int i=0;i<100000;i++) { |
|
192 ucx_avl_put(tree3, i, data1); |
|
193 } |
|
194 for(int i=100000-1;i>=0;i--) { |
|
195 ucx_avl_remove(tree3, i); |
|
196 } |
|
197 UCX_TEST_ASSERT(tree3->root == NULL, "root not NULL (tree3)"); |
|
198 UCX_TEST_ASSERT(check_tree(tree3->root), "check_tree failed (tree3)"); |
|
199 |
|
200 ucx_avl_put(tree4, 1, data1); |
|
201 ucx_avl_remove(tree4, 1); |
|
202 UCX_TEST_ASSERT(check_tree(tree4->root), "check_tree failed (tree4)"); |
|
203 UCX_TEST_ASSERT(tree4->root == NULL, "root not NULL (tree4)"); |
|
204 UCX_TEST_END |
|
205 |
|
206 ucx_avl_free(tree1); |
|
207 ucx_avl_free(tree2); |
|
208 ucx_avl_free(tree3); |
|
209 ucx_avl_free(tree4); |
|
210 } |