56 ucx_array_free(&array); |
56 ucx_array_free(&array); |
57 } |
57 } |
58 |
58 |
59 UCX_TEST(test_ucx_array_append) { |
59 UCX_TEST(test_ucx_array_append) { |
60 UcxArray array = ucx_array_new(16, sizeof(int)); |
60 UcxArray array = ucx_array_new(16, sizeof(int)); |
|
61 int *elements; |
61 |
62 |
62 int x = 42; |
63 int x = 42; |
63 ucx_array_append(&array, &x); |
64 ucx_array_append(&array, &x); |
64 UCX_TEST_BEGIN |
65 UCX_TEST_BEGIN |
65 |
66 |
66 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42, "failed"); |
67 elements = array.data; |
|
68 UCX_TEST_ASSERT(elements[0] == 42, "failed"); |
67 |
69 |
68 x = 13; |
70 x = 13; |
69 ucx_array_append(&array, &x); |
71 ucx_array_append(&array, &x); |
70 |
72 |
|
73 elements = array.data; |
71 UCX_TEST_ASSERT(array.size == 2, "incorrect size after append"); |
74 UCX_TEST_ASSERT(array.size == 2, "incorrect size after append"); |
72 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 13, "failed"); |
75 UCX_TEST_ASSERT(elements[1] == 13, "failed"); |
73 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42, |
76 UCX_TEST_ASSERT(elements[0] == 42, |
74 "append corrupted previously inserted data"); |
77 "append corrupted previously inserted data"); |
75 |
78 |
76 ucx_array_append(&array, NULL); |
79 ucx_array_append(&array, NULL); |
77 |
80 |
|
81 elements = array.data; |
78 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL append"); |
82 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL append"); |
79 UCX_TEST_ASSERT(ucx_array_at_int(array, 2) == 0, "element is not zeroed"); |
83 UCX_TEST_ASSERT(elements[2] == 0, "element is not zeroed"); |
80 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42, |
84 UCX_TEST_ASSERT(elements[0] == 42, |
81 "NULL append corrupted previously inserted data"); |
85 "NULL append corrupted previously inserted data"); |
82 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 13, |
86 UCX_TEST_ASSERT(elements[1] == 13, |
83 "NULL append corrupted previously inserted data"); |
87 "NULL append corrupted previously inserted data"); |
84 |
88 |
85 UCX_TEST_END |
89 UCX_TEST_END |
86 |
90 |
87 ucx_array_free(&array); |
91 ucx_array_free(&array); |
88 } |
92 } |
89 |
93 |
90 UCX_TEST(test_ucx_array_prepend) { |
94 UCX_TEST(test_ucx_array_prepend) { |
|
95 int *elems; |
91 UcxArray array = ucx_array_new(16, sizeof(int)); |
96 UcxArray array = ucx_array_new(16, sizeof(int)); |
92 |
97 |
93 int x = 42; |
98 int x = 42; |
94 ucx_array_prepend(&array, &x); |
99 ucx_array_prepend(&array, &x); |
95 UCX_TEST_BEGIN |
100 UCX_TEST_BEGIN |
96 |
101 |
97 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 42, "failed"); |
102 elems = array.data; |
|
103 UCX_TEST_ASSERT(elems[0] == 42, "failed"); |
98 |
104 |
99 x = 13; |
105 x = 13; |
100 ucx_array_prepend(&array, &x); |
106 ucx_array_prepend(&array, &x); |
101 |
107 |
|
108 elems = array.data; |
102 UCX_TEST_ASSERT(array.size == 2, "incorrect size after prepend"); |
109 UCX_TEST_ASSERT(array.size == 2, "incorrect size after prepend"); |
103 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 13, "failed"); |
110 UCX_TEST_ASSERT(elems[0] == 13, "failed"); |
104 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 42, |
111 UCX_TEST_ASSERT(elems[1] == 42, |
105 "prepend corrupted previously inserted data"); |
112 "prepend corrupted previously inserted data"); |
106 |
113 |
107 ucx_array_prepend(&array, NULL); |
114 ucx_array_prepend(&array, NULL); |
108 |
115 |
|
116 elems = array.data; |
109 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL prepend"); |
117 UCX_TEST_ASSERT(array.size == 3, "incorrect size after NULL prepend"); |
110 UCX_TEST_ASSERT(ucx_array_at_int(array, 0) == 0, "element is not zeroed"); |
118 UCX_TEST_ASSERT(elems[0] == 0, "element is not zeroed"); |
111 UCX_TEST_ASSERT(ucx_array_at_int(array, 1) == 13, |
119 UCX_TEST_ASSERT(elems[1] == 13, |
112 "NULL prepend corrupted previously inserted data"); |
120 "NULL prepend corrupted previously inserted data"); |
113 UCX_TEST_ASSERT(ucx_array_at_int(array, 2) == 42, |
121 UCX_TEST_ASSERT(elems[2] == 42, |
114 "NULL prepend corrupted previously inserted data"); |
122 "NULL prepend corrupted previously inserted data"); |
115 |
123 |
116 UCX_TEST_END |
124 UCX_TEST_END |
117 |
125 |
118 ucx_array_free(&array); |
126 ucx_array_free(&array); |
119 } |
127 } |
120 |
128 |
121 UCX_TEST(test_ucx_array_set) { |
129 UCX_TEST(test_ucx_array_set) { |
122 UcxArray array = ucx_array_new(16, sizeof(int)); |
130 int *elems; |
|
131 UcxArray array = ucx_array_new(16, sizeof(int)); |
|
132 |
123 |
133 |
124 int x = 42; |
134 int x = 42; |
125 |
135 |
126 UCX_TEST_BEGIN |
136 UCX_TEST_BEGIN |
127 |
137 |
128 ucx_array_set(&array, 7, &x); |
138 ucx_array_set(&array, 7, &x); |
129 UCX_TEST_ASSERT(ucx_array_at_int(array, 7) == 42, "failed"); |
139 |
|
140 elems = array.data; |
|
141 UCX_TEST_ASSERT(elems[7] == 42, "failed"); |
130 UCX_TEST_ASSERT(array.size >= 8, "array not resized on set"); |
142 UCX_TEST_ASSERT(array.size >= 8, "array not resized on set"); |
131 UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily"); |
143 UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily"); |
132 |
144 |
133 x = 13; |
145 x = 13; |
134 ucx_array_set(&array, 27, &x); |
146 ucx_array_set(&array, 27, &x); |
135 |
147 |
136 UCX_TEST_ASSERT(ucx_array_at_int(array, 27) == 13, "failed"); |
148 elems = array.data; |
|
149 UCX_TEST_ASSERT(elems[27] == 13, "failed"); |
137 UCX_TEST_ASSERT(array.size == 28, "array not resized on set"); |
150 UCX_TEST_ASSERT(array.size == 28, "array not resized on set"); |
138 UCX_TEST_ASSERT(array.capacity == 28, "capacity not grown"); |
151 UCX_TEST_ASSERT(array.capacity == 28, "capacity not grown"); |
139 |
152 |
140 ucx_array_set(&array, 7, NULL); |
153 ucx_array_set(&array, 7, NULL); |
141 |
154 |
142 UCX_TEST_ASSERT(ucx_array_at_int(array, 7) == 0, "not zeroed on NULL set"); |
155 elems = array.data; |
|
156 UCX_TEST_ASSERT(elems[7] == 0, "not zeroed on NULL set"); |
143 |
157 |
144 UCX_TEST_END |
158 UCX_TEST_END |
145 |
159 |
146 ucx_array_free(&array); |
160 ucx_array_free(&array); |
147 } |
161 } |
150 UcxArray a1 = ucx_array_new(16, sizeof(int)); |
164 UcxArray a1 = ucx_array_new(16, sizeof(int)); |
151 UcxArray a2 = ucx_array_new(16, sizeof(int)); |
165 UcxArray a2 = ucx_array_new(16, sizeof(int)); |
152 UcxArray a3 = ucx_array_new(16, sizeof(long int)); |
166 UcxArray a3 = ucx_array_new(16, sizeof(long int)); |
153 UcxArray a4 = ucx_array_new(16, sizeof(int)); |
167 UcxArray a4 = ucx_array_new(16, sizeof(int)); |
154 |
168 |
|
169 int *intelems; |
|
170 long int *longintelems; |
|
171 |
155 a1.size = 5; |
172 a1.size = 5; |
156 ucx_array_at_int(a1, 0) = 47; |
173 intelems = a1.data; |
157 ucx_array_at_int(a1, 1) = 11; |
174 intelems[0] = 47; |
158 ucx_array_at_int(a1, 2) = 0; |
175 intelems[1] = 11; |
159 ucx_array_at_int(a1, 3) = 8; |
176 intelems[2] = 0; |
160 ucx_array_at_int(a1, 4) = 15; |
177 intelems[3] = 8; |
|
178 intelems[4] = 15; |
161 a2.size = 5; |
179 a2.size = 5; |
162 ucx_array_at_int(a2, 0) = 47; |
180 intelems = a2.data; |
163 ucx_array_at_int(a2, 1) = 11; |
181 intelems[0] = 47; |
164 ucx_array_at_int(a2, 2) = 0; |
182 intelems[1] = 11; |
165 ucx_array_at_int(a2, 3) = 8; |
183 intelems[2] = 0; |
166 ucx_array_at_int(a2, 4) = 15; |
184 intelems[3] = 8; |
|
185 intelems[4] = 15; |
167 a3.size = 5; |
186 a3.size = 5; |
168 ucx_array_at_longint(a3, 0) = 47; |
187 longintelems = a3.data; |
169 ucx_array_at_longint(a3, 1) = 11; |
188 longintelems[0] = 47; |
170 ucx_array_at_longint(a3, 2) = 0; |
189 longintelems[1] = 11; |
171 ucx_array_at_longint(a3, 3) = 8; |
190 longintelems[2] = 0; |
172 ucx_array_at_longint(a3, 4) = 15; |
191 longintelems[3] = 8; |
|
192 longintelems[4] = 15; |
173 a4.size = 5; |
193 a4.size = 5; |
174 ucx_array_at_int(a4, 0) = 47; |
194 intelems = a4.data; |
175 ucx_array_at_int(a4, 1) = 11; |
195 intelems[0] = 47; |
176 ucx_array_at_int(a4, 2) = -6; |
196 intelems[1] = 11; |
177 ucx_array_at_int(a4, 3) = 8; |
197 intelems[2] = -6; |
178 ucx_array_at_int(a4, 4) = 15; |
198 intelems[3] = 8; |
|
199 intelems[4] = 15; |
179 |
200 |
180 UCX_TEST_BEGIN |
201 UCX_TEST_BEGIN |
181 |
202 |
182 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, ucx_cmp_int, NULL), "failed"); |
203 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, ucx_cmp_int, NULL), "failed"); |
183 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, ucx_cmp_int, NULL), "failed"); |
204 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, ucx_cmp_int, NULL), "failed"); |
200 } |
221 } |
201 |
222 |
202 UCX_TEST(test_ucx_array_concat) { |
223 UCX_TEST(test_ucx_array_concat) { |
203 UcxArray a1 = ucx_array_new(16, sizeof(int)); |
224 UcxArray a1 = ucx_array_new(16, sizeof(int)); |
204 UcxArray a2 = ucx_array_new(16, sizeof(int)); |
225 UcxArray a2 = ucx_array_new(16, sizeof(int)); |
|
226 int *elems; |
205 |
227 |
206 a1.size = 2; |
228 a1.size = 2; |
207 ucx_array_at_int(a1, 0) = 47; |
229 elems = a1.data; |
208 ucx_array_at_int(a1, 1) = 11; |
230 elems[0] = 47; |
|
231 elems[1] = 11; |
209 a2.size = 3; |
232 a2.size = 3; |
210 ucx_array_at_int(a2, 0) = 0; |
233 elems = a2.data; |
211 ucx_array_at_int(a2, 1) = 8; |
234 elems[0] = 0; |
212 ucx_array_at_int(a2, 2) = 15; |
235 elems[1] = 8; |
|
236 elems[2] = 15; |
213 |
237 |
214 UCX_TEST_BEGIN |
238 UCX_TEST_BEGIN |
215 |
239 |
216 UCX_TEST_ASSERT(!ucx_array_concat(&a1, &a2), "failed"); |
240 UCX_TEST_ASSERT(!ucx_array_concat(&a1, &a2), "failed"); |
217 UCX_TEST_ASSERT(a1.size == 5, "failed"); |
241 UCX_TEST_ASSERT(a1.size == 5, "failed"); |
218 UCX_TEST_ASSERT(ucx_array_at_int(a1, 0) == 47, "failed"); |
242 elems = a1.data; |
219 UCX_TEST_ASSERT(ucx_array_at_int(a1, 1) == 11, "failed"); |
243 UCX_TEST_ASSERT(elems[0] == 47, "failed"); |
220 UCX_TEST_ASSERT(ucx_array_at_int(a1, 2) == 0, "failed"); |
244 UCX_TEST_ASSERT(elems[1] == 11, "failed"); |
221 UCX_TEST_ASSERT(ucx_array_at_int(a1, 3) == 8, "failed"); |
245 UCX_TEST_ASSERT(elems[2] == 0, "failed"); |
222 UCX_TEST_ASSERT(ucx_array_at_int(a1, 4) == 15, "failed"); |
246 UCX_TEST_ASSERT(elems[3] == 8, "failed"); |
|
247 UCX_TEST_ASSERT(elems[4] == 15, "failed"); |
223 |
248 |
224 a1.elemsize *= 2; |
249 a1.elemsize *= 2; |
225 UCX_TEST_ASSERT(ucx_array_concat(&a1, &a2), |
250 UCX_TEST_ASSERT(ucx_array_concat(&a1, &a2), |
226 "arrays of different element size must not be concatenated"); |
251 "arrays of different element size must not be concatenated"); |
227 UCX_TEST_ASSERT(a1.size == 5, |
252 UCX_TEST_ASSERT(a1.size == 5, |
315 ucx_array_free(&array); |
319 ucx_array_free(&array); |
316 } |
320 } |
317 |
321 |
318 UCX_TEST(test_ucx_array_remove) { |
322 UCX_TEST(test_ucx_array_remove) { |
319 UcxArray array = ucx_array_new(16, sizeof(int)); |
323 UcxArray array = ucx_array_new(16, sizeof(int)); |
|
324 int *elems; |
320 |
325 |
321 array.size = 5; |
326 array.size = 5; |
322 ucx_array_at_int(array, 0) = 47; |
327 elems = array.data; |
323 ucx_array_at_int(array, 1) = 11; |
328 elems[0] = 47; |
324 ucx_array_at_int(array, 2) = 0; |
329 elems[1] = 11; |
325 ucx_array_at_int(array, 3) = 8; |
330 elems[2] = 0; |
326 ucx_array_at_int(array, 4) = 15; |
331 elems[3] = 8; |
|
332 elems[4] = 15; |
327 |
333 |
328 UCX_TEST_BEGIN |
334 UCX_TEST_BEGIN |
329 |
335 |
330 ucx_array_remove(&array, 2); |
336 ucx_array_remove(&array, 2); |
|
337 elems = array.data; |
331 UCX_TEST_ASSERT( |
338 UCX_TEST_ASSERT( |
332 ucx_array_at_int(array, 0) == 47 && |
339 elems[0] == 47 && |
333 ucx_array_at_int(array, 1) == 11 && |
340 elems[1] == 11 && |
334 ucx_array_at_int(array, 2) == 8 && |
341 elems[2] == 8 && |
335 ucx_array_at_int(array, 3) == 15, |
342 elems[3] == 15, |
336 "wrong contents after remove"); |
343 "wrong contents after remove"); |
337 UCX_TEST_ASSERT(array.size == 4, "wrong size after remove"); |
344 UCX_TEST_ASSERT(array.size == 4, "wrong size after remove"); |
338 |
345 |
339 ucx_array_remove_fast(&array, 1); |
346 ucx_array_remove_fast(&array, 1); |
|
347 elems = array.data; |
340 UCX_TEST_ASSERT( |
348 UCX_TEST_ASSERT( |
341 ucx_array_at_int(array, 0) == 47 && |
349 elems[0] == 47 && |
342 ucx_array_at_int(array, 1) == 15 && |
350 elems[1] == 15 && |
343 ucx_array_at_int(array, 2) == 8, |
351 elems[2] == 8, |
344 "wrong contents after fast remove"); |
352 "wrong contents after fast remove"); |
345 UCX_TEST_ASSERT(array.size == 3, "wrong size after fast remove"); |
353 UCX_TEST_ASSERT(array.size == 3, "wrong size after fast remove"); |
346 |
354 |
347 UCX_TEST_END |
355 UCX_TEST_END |
348 ucx_array_free(&array); |
356 ucx_array_free(&array); |
349 } |
357 } |
350 |
358 |
351 UCX_TEST(test_ucx_array_clone) { |
359 UCX_TEST(test_ucx_array_clone) { |
352 |
360 UcxArray array = ucx_array_new(16, sizeof(int)); |
353 UcxArray array = ucx_array_new(16, sizeof(int)); |
361 int *elems; |
354 |
362 |
355 array.size = 5; |
363 array.size = 5; |
356 ucx_array_at_int(array, 0) = 47; |
364 elems = array.data; |
357 ucx_array_at_int(array, 1) = 11; |
365 elems[0] = 47; |
358 ucx_array_at_int(array, 2) = 0; |
366 elems[1] = 11; |
359 ucx_array_at_int(array, 3) = 8; |
367 elems[2] = 0; |
360 ucx_array_at_int(array, 4) = 15; |
368 elems[3] = 8; |
|
369 elems[4] = 15; |
361 |
370 |
362 UcxArray copy = ucx_array_clone(array); |
371 UcxArray copy = ucx_array_clone(array); |
363 UCX_TEST_BEGIN |
372 UCX_TEST_BEGIN |
364 |
373 |
365 UCX_TEST_ASSERT(array.data != copy.data, "no true copy"); |
374 UCX_TEST_ASSERT(array.data != copy.data, "no true copy"); |
373 |
382 |
374 ucx_array_free(&array); |
383 ucx_array_free(&array); |
375 ucx_array_free(©); |
384 ucx_array_free(©); |
376 } |
385 } |
377 |
386 |
|
387 static int ucx_cmp_int_reverse(const void* x, const void* y, void* data) { |
|
388 return -ucx_cmp_int(x,y,data); |
|
389 } |
|
390 |
378 UCX_TEST(test_ucx_array_sort) { |
391 UCX_TEST(test_ucx_array_sort) { |
379 UcxArray array = ucx_array_new(16, sizeof(int)); |
392 int *elems; |
|
393 |
|
394 UcxArray array = ucx_array_new(16, sizeof(int)); |
380 array.size = 5; |
395 array.size = 5; |
381 ucx_array_at_int(array, 0) = 47; |
396 elems = array.data; |
382 ucx_array_at_int(array, 1) = 11; |
397 elems[0] = 47; |
383 ucx_array_at_int(array, 2) = 0; |
398 elems[1] = 11; |
384 ucx_array_at_int(array, 3) = 8; |
399 elems[2] = 0; |
385 ucx_array_at_int(array, 4) = 15; |
400 elems[3] = 8; |
|
401 elems[4] = 15; |
386 |
402 |
387 UcxArray expected = ucx_array_new(16, sizeof(int)); |
403 UcxArray expected = ucx_array_new(16, sizeof(int)); |
388 expected.size = 5; |
404 expected.size = 5; |
389 ucx_array_at_int(expected, 0) = 0; |
405 elems = expected.data; |
390 ucx_array_at_int(expected, 1) = 8; |
406 elems[0] = 0; |
391 ucx_array_at_int(expected, 2) = 11; |
407 elems[1] = 8; |
392 ucx_array_at_int(expected, 3) = 15; |
408 elems[2] = 11; |
393 ucx_array_at_int(expected, 4) = 47; |
409 elems[3] = 15; |
|
410 elems[4] = 47; |
|
411 |
|
412 UcxArray expectedrev = ucx_array_new(16, sizeof(int)); |
|
413 expectedrev.size = 5; |
|
414 elems = expectedrev.data; |
|
415 elems[0] = 47; |
|
416 elems[1] = 15; |
|
417 elems[2] = 11; |
|
418 elems[3] = 8; |
|
419 elems[4] = 0; |
394 |
420 |
395 |
421 |
396 UCX_TEST_BEGIN |
422 UCX_TEST_BEGIN |
397 void* original_ptr = array.data; |
423 void* original_ptr = array.data; |
398 ucx_array_sort(array, ucx_cmp_int, NULL); |
424 ucx_array_sort(array, ucx_cmp_int, NULL); |
399 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed"); |
425 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed"); |
400 UCX_TEST_ASSERT(array.size == 5, "size corrupted"); |
426 UCX_TEST_ASSERT(array.size == 5, "size corrupted"); |
401 UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate"); |
427 UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate"); |
402 |
428 |
|
429 ucx_array_sort(array, ucx_cmp_int_reverse, NULL); |
|
430 UCX_TEST_ASSERT(ucx_array_equals(array, expectedrev, NULL, NULL), "failed"); |
|
431 |
403 ucx_array_reserve(&array, 32); |
432 ucx_array_reserve(&array, 32); |
404 ucx_array_reserve(&expected, 32); |
433 ucx_array_reserve(&expected, 32); |
405 array.size = expected.size = 32; |
434 array.size = expected.size = 32; |
406 for (size_t i = 0 ; i < 32 ; i++) { |
435 for (size_t i = 0 ; i < 32 ; i++) { |
407 ucx_array_at_int(array, i) = ((i%2==0)?-1:1) * ((int) i); |
436 ((int*)array.data)[i]= ((i%2==0)?-1:1) * ((int) i); |
408 ucx_array_at_int(expected, i) = (-30+2*i) - (i > 15 ? 1 : 0); |
437 ((int*)expected.data)[i] = (-30+2*i) - (i > 15 ? 1 : 0); |
409 } |
438 } |
410 |
439 |
411 ucx_array_sort(array, ucx_cmp_int, NULL); |
440 /* dummy third argument to trigger a possible fallback for qsort_s */ |
|
441 ucx_array_sort(array, ucx_cmp_int, array.data); |
412 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), |
442 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), |
413 "failed for bigger arrays"); |
443 "failed for bigger arrays"); |
414 UCX_TEST_END |
444 UCX_TEST_END |
415 |
445 |
416 ucx_array_free(&expected); |
446 ucx_array_free(&expected); |
417 ucx_array_free(&array); |
447 ucx_array_free(&array); |
418 } |
448 } |
419 |
449 |
420 UCX_TEST(test_ucx_array_autogrow) { |
450 UCX_TEST(test_ucx_array_autogrow) { |
|
451 int *elems; |
421 UcxArray array = ucx_array_new(4, sizeof(int)); |
452 UcxArray array = ucx_array_new(4, sizeof(int)); |
422 array.size = 3; |
453 array.size = 3; |
423 ucx_array_at_int(array, 0) = 47; |
454 elems = array.data; |
424 ucx_array_at_int(array, 1) = 11; |
455 elems[0] = 47; |
|
456 elems[1] = 11; |
425 int x = 5; |
457 int x = 5; |
426 |
458 |
427 UCX_TEST_BEGIN |
459 UCX_TEST_BEGIN |
428 |
460 |
429 void* oldptr = array.data; |
461 void* oldptr = array.data; |
430 |
462 |
431 ucx_array_append(&array, &x); |
463 ucx_array_append(&array, &x); |
432 UCX_TEST_ASSERT(array.capacity == 4 && array.data == oldptr, |
464 UCX_TEST_ASSERT(array.capacity == 4 && array.data == oldptr, |
433 "array should not grow too early"); |
465 "array should not grow too early"); |
434 ucx_array_append(&array, &x); |
466 ucx_array_append(&array, &x); |
|
467 elems = array.data; |
435 UCX_TEST_ASSERT(array.capacity == 8, "array did not grow"); |
468 UCX_TEST_ASSERT(array.capacity == 8, "array did not grow"); |
436 UCX_TEST_ASSERT(array.size == 5, "incorrect size after grow"); |
469 UCX_TEST_ASSERT(array.size == 5, "incorrect size after grow"); |
437 UCX_TEST_ASSERT(ucx_array_at_int(array, 3) == 5 && |
470 UCX_TEST_ASSERT(elems[3] == 5 && elems[4] == 5, "corrupt data"); |
438 ucx_array_at_int(array, 3) == 5, "corrupt data"); |
|
439 |
471 |
440 UCX_TEST_END |
472 UCX_TEST_END |
441 ucx_array_free(&array); |
473 ucx_array_free(&array); |
442 } |
474 } |
443 |
475 |