Tue, 24 Sep 2019 20:16:00 +0200
adds array utility functions for user defined arrays
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2019 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
29 #include "array_tests.h"
30 #include <ucx/utils.h>
32 UCX_TEST(test_ucx_array_free) {
33 UcxArray array = ucx_array_new(16, sizeof(int));
35 UCX_TEST_BEGIN
36 ucx_array_destroy(&array);
37 UCX_TEST_ASSERT(array.data == NULL, "data pointer not NULL after free");
38 UCX_TEST_ASSERT(array.size == 0, "size not zero after free");
39 UCX_TEST_ASSERT(array.capacity == 0, "capacity not zero after free");
40 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(),
41 "allocator corrupted during free");
42 UCX_TEST_END
43 }
45 UCX_TEST(test_ucx_array_new) {
46 UcxArray array = ucx_array_new(16, 47);
48 UCX_TEST_BEGIN
49 UCX_TEST_ASSERT(array.data, "no memory allocated");
50 UCX_TEST_ASSERT(array.size == 0, "size not initially zero");
51 UCX_TEST_ASSERT(array.capacity == 16, "capacity not as requested");
52 UCX_TEST_ASSERT(array.elemsize == 47, "element size not as requested");
53 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(),
54 "array not using the default allocator");
55 UCX_TEST_END
56 ucx_array_destroy(&array);
57 }
59 UCX_TEST(test_ucx_array_append_from) {
60 UcxArray array = ucx_array_new(16, sizeof(int));
61 int *elements;
63 int x = 42;
64 ucx_array_append_from(&array, &x, 1);
65 UCX_TEST_BEGIN
67 elements = array.data;
68 UCX_TEST_ASSERT(elements[0] == 42, "failed");
70 int y[2] = {13, 37};
71 ucx_array_append_from(&array, y, 2);
73 elements = array.data;
74 UCX_TEST_ASSERT(array.size == 3, "incorrect size after append");
75 UCX_TEST_ASSERT(elements[1] == 13, "failed");
76 UCX_TEST_ASSERT(elements[2] == 37, "failed");
77 UCX_TEST_ASSERT(elements[0] == 42,
78 "append corrupted previously inserted data");
80 ucx_array_append_from(&array, NULL, 2);
82 elements = array.data;
83 UCX_TEST_ASSERT(array.size == 5, "incorrect size after NULL append");
84 UCX_TEST_ASSERT(elements[3] == 0, "element is not zeroed");
85 UCX_TEST_ASSERT(elements[4] == 0, "element is not zeroed");
86 UCX_TEST_ASSERT(elements[0] == 42,
87 "NULL append corrupted previously inserted data");
88 UCX_TEST_ASSERT(elements[1] == 13,
89 "NULL append corrupted previously inserted data");
90 UCX_TEST_ASSERT(elements[2] == 37,
91 "NULL append corrupted previously inserted data");
93 UCX_TEST_END
95 ucx_array_destroy(&array);
96 }
98 UCX_TEST(test_ucx_array_prepend_from) {
99 int *elems;
100 UcxArray array = ucx_array_new(16, sizeof(int));
102 int x = 42;
103 ucx_array_prepend_from(&array, &x, 1);
104 UCX_TEST_BEGIN
106 elems = array.data;
107 UCX_TEST_ASSERT(elems[0] == 42, "failed");
109 int y[2] = {13, 37};
110 ucx_array_prepend_from(&array, y, 2);
112 elems = array.data;
113 UCX_TEST_ASSERT(array.size == 3, "incorrect size after prepend");
114 UCX_TEST_ASSERT(elems[0] == 13, "failed");
115 UCX_TEST_ASSERT(elems[1] == 37, "failed");
116 UCX_TEST_ASSERT(elems[2] == 42,
117 "prepend corrupted previously inserted data");
119 ucx_array_prepend_from(&array, NULL, 2);
121 elems = array.data;
122 UCX_TEST_ASSERT(array.size == 5, "incorrect size after NULL prepend");
123 UCX_TEST_ASSERT(elems[0] == 0, "element is not zeroed");
124 UCX_TEST_ASSERT(elems[1] == 0, "element is not zeroed");
125 UCX_TEST_ASSERT(elems[2] == 13,
126 "NULL prepend corrupted previously inserted data");
127 UCX_TEST_ASSERT(elems[3] == 37,
128 "NULL prepend corrupted previously inserted data");
129 UCX_TEST_ASSERT(elems[4] == 42,
130 "NULL prepend corrupted previously inserted data");
132 UCX_TEST_END
134 ucx_array_destroy(&array);
135 }
137 UCX_TEST(test_ucx_array_set_from) {
138 int *elems;
139 UcxArray array = ucx_array_new(16, sizeof(int));
141 int x = 42;
143 UCX_TEST_BEGIN
145 ucx_array_set_from(&array, 7, &x, 1);
147 elems = array.data;
148 UCX_TEST_ASSERT(elems[7] == 42, "failed");
149 UCX_TEST_ASSERT(array.size >= 8, "array not resized on set");
150 UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily");
152 int y[2] = {13, 37};
153 ucx_array_set_from(&array, 27, y, 2);
155 elems = array.data;
156 UCX_TEST_ASSERT(elems[27] == 13, "failed");
157 UCX_TEST_ASSERT(elems[28] == 37, "failed");
158 UCX_TEST_ASSERT(array.size == 29, "array not resized on set");
159 UCX_TEST_ASSERT(array.capacity == 32, "capacity not grown");
161 ucx_array_set_from(&array, 7, NULL, 2);
163 elems = array.data;
164 UCX_TEST_ASSERT(elems[7] == 0, "not zeroed on NULL set");
165 UCX_TEST_ASSERT(elems[8] == 0, "not zeroed on NULL set");
167 UCX_TEST_END
169 ucx_array_destroy(&array);
170 }
172 UCX_TEST(test_ucx_array_append) {
173 UcxArray array = ucx_array_new(16, sizeof(int));
174 int *elements;
176 ucx_array_append(&array, 42);
177 UCX_TEST_BEGIN
179 elements = array.data;
180 UCX_TEST_ASSERT(elements[0] == 42, "failed");
182 ucx_array_append(&array, 13);
183 ucx_array_append(&array, 37);
185 elements = array.data;
186 UCX_TEST_ASSERT(array.size == 3, "incorrect size after append");
187 UCX_TEST_ASSERT(elements[1] == 13, "failed");
188 UCX_TEST_ASSERT(elements[2] == 37, "failed");
189 UCX_TEST_ASSERT(elements[0] == 42,
190 "append corrupted previously inserted data");
192 UCX_TEST_END
194 ucx_array_destroy(&array);
195 }
197 UCX_TEST(test_ucx_array_prepend) {
198 int *elems;
199 UcxArray array = ucx_array_new(16, sizeof(int));
201 ucx_array_prepend(&array, 42);
202 UCX_TEST_BEGIN
204 elems = array.data;
205 UCX_TEST_ASSERT(elems[0] == 42, "failed");
207 ucx_array_prepend(&array, 37);
208 ucx_array_prepend(&array, 13);
210 elems = array.data;
211 UCX_TEST_ASSERT(array.size == 3, "incorrect size after prepend");
212 UCX_TEST_ASSERT(elems[0] == 13, "failed");
213 UCX_TEST_ASSERT(elems[1] == 37, "failed");
214 UCX_TEST_ASSERT(elems[2] == 42,
215 "prepend corrupted previously inserted data");
217 UCX_TEST_END
219 ucx_array_destroy(&array);
220 }
222 UCX_TEST(test_ucx_array_set) {
223 int *elems;
224 UcxArray array = ucx_array_new(16, sizeof(int));
226 UCX_TEST_BEGIN
228 ucx_array_set(&array, 7, 42);
230 elems = array.data;
231 UCX_TEST_ASSERT(elems[7] == 42, "failed");
232 UCX_TEST_ASSERT(array.size == 8, "array not resized on set");
233 UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily");
235 ucx_array_set(&array, 27, 13);
236 ucx_array_set(&array, 28, 37);
238 elems = array.data;
239 UCX_TEST_ASSERT(elems[27] == 13, "failed");
240 UCX_TEST_ASSERT(elems[28] == 37, "failed");
241 UCX_TEST_ASSERT(array.size == 29, "array not resized on set");
242 UCX_TEST_ASSERT(array.capacity == 32, "capacity not grown");
244 UCX_TEST_END
246 ucx_array_destroy(&array);
247 }
249 UCX_TEST(test_ucx_array_equals) {
250 UcxArray a1 = ucx_array_new(16, sizeof(int32_t));
251 UcxArray a2 = ucx_array_new(16, sizeof(int32_t));
252 UcxArray a3 = ucx_array_new(16, sizeof(int64_t));
253 UcxArray a4 = ucx_array_new(16, sizeof(int32_t));
255 int32_t *intelems;
256 int64_t *longintelems;
258 a1.size = 5;
259 intelems = a1.data;
260 intelems[0] = 47;
261 intelems[1] = 11;
262 intelems[2] = 0;
263 intelems[3] = 8;
264 intelems[4] = 15;
265 a2.size = 5;
266 intelems = a2.data;
267 intelems[0] = 47;
268 intelems[1] = 11;
269 intelems[2] = 0;
270 intelems[3] = 8;
271 intelems[4] = 15;
272 a3.size = 5;
273 longintelems = a3.data;
274 longintelems[0] = 47;
275 longintelems[1] = 11;
276 longintelems[2] = 0;
277 longintelems[3] = 8;
278 longintelems[4] = 15;
279 a4.size = 5;
280 intelems = a4.data;
281 intelems[0] = 47;
282 intelems[1] = 11;
283 intelems[2] = -6;
284 intelems[3] = 8;
285 intelems[4] = 15;
287 UCX_TEST_BEGIN
289 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, ucx_cmp_int32, NULL), "failed");
290 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, ucx_cmp_int32, NULL), "failed");
291 UCX_TEST_ASSERT(!ucx_array_equals(a4, a1, ucx_cmp_int32, NULL), "failed");
292 UCX_TEST_ASSERT(!ucx_array_equals(a1, a3, ucx_cmp_int64, NULL),
293 "comparing arrays of different element size shall fail");
294 UCX_TEST_ASSERT(!ucx_array_equals(a3, a1, ucx_cmp_int64, NULL),
295 "comparing arrays of different element size shall fail");
297 UCX_TEST_ASSERT(ucx_array_equals(a1, a2, NULL, NULL),
298 "compare using memcmp() failed");
299 UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, NULL, NULL),
300 "compare using memcmp() failed");
302 UCX_TEST_END
303 ucx_array_destroy(&a1);
304 ucx_array_destroy(&a2);
305 ucx_array_destroy(&a3);
306 ucx_array_destroy(&a4);
307 }
309 UCX_TEST(test_ucx_array_concat) {
310 UcxArray a1 = ucx_array_new(16, sizeof(int));
311 UcxArray a2 = ucx_array_new(16, sizeof(int));
312 int *elems;
314 a1.size = 2;
315 elems = a1.data;
316 elems[0] = 47;
317 elems[1] = 11;
318 a2.size = 3;
319 elems = a2.data;
320 elems[0] = 0;
321 elems[1] = 8;
322 elems[2] = 15;
324 UCX_TEST_BEGIN
326 UCX_TEST_ASSERT(!ucx_array_concat(&a1, &a2), "failed");
327 UCX_TEST_ASSERT(a1.size == 5, "failed");
328 elems = a1.data;
329 UCX_TEST_ASSERT(elems[0] == 47, "failed");
330 UCX_TEST_ASSERT(elems[1] == 11, "failed");
331 UCX_TEST_ASSERT(elems[2] == 0, "failed");
332 UCX_TEST_ASSERT(elems[3] == 8, "failed");
333 UCX_TEST_ASSERT(elems[4] == 15, "failed");
335 a1.elemsize *= 2;
336 UCX_TEST_ASSERT(ucx_array_concat(&a1, &a2),
337 "arrays of different element size must not be concatenated");
338 UCX_TEST_ASSERT(a1.size == 5,
339 "arrays of different element size must not be concatenated");
341 UCX_TEST_END
342 ucx_array_destroy(&a1);
343 ucx_array_destroy(&a2);
344 }
346 UCX_TEST(test_ucx_array_at) {
347 UcxArray array = ucx_array_new(16, sizeof(int));
349 int x[3] = {42, 13, 5};
350 ucx_array_append_from(&array, x, 3);
352 UCX_TEST_BEGIN
354 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 1) == 13, "failed");
355 *(int*)ucx_array_at(array, 1) = 80;
356 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 1) == 80, "assignment failed");
358 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 0) == 42, "corrupted data");
359 UCX_TEST_ASSERT(*(int*)ucx_array_at(array, 2) == 5, "corrupted data");
361 UCX_TEST_END
363 ucx_array_destroy(&array);
364 }
366 UCX_TEST(test_ucx_array_find) {
367 UcxArray array = ucx_array_new(16, sizeof(int));
368 int *elems;
370 array.size = 5;
371 elems = array.data;
372 elems[0] = 47;
373 elems[1] = 11;
374 elems[2] = 0;
375 elems[3] = 8;
376 elems[4] = 15;
378 int x = 8;
379 int y = 90;
381 UCX_TEST_BEGIN
383 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&x,ucx_cmp_int,NULL) == 3,
384 "doesn't find element");
385 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&y,ucx_cmp_int,NULL) == 5,
386 "finds non-existing element");
388 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&x,NULL,NULL) == 3,
389 "failed using memcmp()");
390 UCX_TEST_ASSERT(ucx_array_find(array,(void*)&y,NULL,NULL) == 5,
391 "failed using memcmp()");
393 UCX_TEST_END
394 ucx_array_destroy(&array);
395 }
397 UCX_TEST(test_ucx_array_contains) {
398 UcxArray array = ucx_array_new(16, sizeof(int));
399 int *elems;
401 array.size = 5;
402 elems = array.data;
403 elems[0] = 47;
404 elems[1] = 11;
405 elems[2] = 0;
406 elems[3] = 8;
407 elems[4] = 15;
409 int x = 8;
410 int y = 90;
412 UCX_TEST_BEGIN
414 UCX_TEST_ASSERT(ucx_array_contains(array,(void*)&x,ucx_cmp_int,NULL),
415 "false negative");
416 UCX_TEST_ASSERT(!ucx_array_contains(array,(void*)&y,ucx_cmp_int,NULL),
417 "false positive");
419 UCX_TEST_ASSERT(ucx_array_contains(array,(void*)&x,NULL,NULL),
420 "false negative using memcmp()");
421 UCX_TEST_ASSERT(!ucx_array_contains(array,(void*)&y,NULL,NULL),
422 "false positive using memcmp()");
424 UCX_TEST_END
425 ucx_array_destroy(&array);
426 }
428 UCX_TEST(test_ucx_array_remove) {
429 UcxArray array = ucx_array_new(16, sizeof(int));
430 int *elems;
432 array.size = 5;
433 elems = array.data;
434 elems[0] = 47;
435 elems[1] = 11;
436 elems[2] = 0;
437 elems[3] = 8;
438 elems[4] = 15;
440 UCX_TEST_BEGIN
442 ucx_array_remove(&array, 2);
443 elems = array.data;
444 UCX_TEST_ASSERT(
445 elems[0] == 47 &&
446 elems[1] == 11 &&
447 elems[2] == 8 &&
448 elems[3] == 15,
449 "wrong contents after remove");
450 UCX_TEST_ASSERT(array.size == 4, "wrong size after remove");
452 ucx_array_remove_fast(&array, 1);
453 elems = array.data;
454 UCX_TEST_ASSERT(
455 elems[0] == 47 &&
456 elems[1] == 15 &&
457 elems[2] == 8,
458 "wrong contents after fast remove");
459 UCX_TEST_ASSERT(array.size == 3, "wrong size after fast remove");
461 UCX_TEST_END
462 ucx_array_destroy(&array);
463 }
465 UCX_TEST(test_ucx_array_clone) {
466 UcxArray array = ucx_array_new(16, sizeof(int));
467 int *elems;
469 array.size = 5;
470 elems = array.data;
471 elems[0] = 47;
472 elems[1] = 11;
473 elems[2] = 0;
474 elems[3] = 8;
475 elems[4] = 15;
477 UcxArray copy = ucx_array_clone(array);
478 UCX_TEST_BEGIN
480 UCX_TEST_ASSERT(array.data != copy.data, "no true copy");
481 UCX_TEST_ASSERT(array.size == copy.size, "size mismatch");
482 UCX_TEST_ASSERT(array.capacity == copy.capacity, "capacity mismatch");
483 UCX_TEST_ASSERT(array.elemsize == copy.elemsize, "element size mismatch");
484 UCX_TEST_ASSERT(array.allocator == copy.allocator, "allocator mismatch");
485 UCX_TEST_ASSERT(ucx_array_equals(array, copy, ucx_cmp_int, NULL), "failed");
487 UCX_TEST_END
489 ucx_array_destroy(&array);
490 ucx_array_destroy(©);
491 }
493 static int ucx_cmp_int_reverse(const void* x, const void* y, void* data) {
494 return -ucx_cmp_int(x,y,data);
495 }
497 UCX_TEST(test_ucx_array_sort) {
498 int *elems;
500 UcxArray array = ucx_array_new(16, sizeof(int));
501 array.size = 5;
502 elems = array.data;
503 elems[0] = 47;
504 elems[1] = 11;
505 elems[2] = 0;
506 elems[3] = 8;
507 elems[4] = 15;
509 UcxArray expected = ucx_array_new(16, sizeof(int));
510 expected.size = 5;
511 elems = expected.data;
512 elems[0] = 0;
513 elems[1] = 8;
514 elems[2] = 11;
515 elems[3] = 15;
516 elems[4] = 47;
518 UcxArray expectedrev = ucx_array_new(16, sizeof(int));
519 expectedrev.size = 5;
520 elems = expectedrev.data;
521 elems[0] = 47;
522 elems[1] = 15;
523 elems[2] = 11;
524 elems[3] = 8;
525 elems[4] = 0;
528 UCX_TEST_BEGIN
529 void* original_ptr = array.data;
530 ucx_array_sort(array, ucx_cmp_int, NULL);
531 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed");
532 UCX_TEST_ASSERT(array.size == 5, "size corrupted");
533 UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate");
535 ucx_array_sort(array, ucx_cmp_int_reverse, NULL);
536 UCX_TEST_ASSERT(ucx_array_equals(array, expectedrev, NULL, NULL), "failed");
538 ucx_array_reserve(&array, 32);
539 ucx_array_reserve(&expected, 32);
540 array.size = expected.size = 32;
541 for (size_t i = 0 ; i < 32 ; i++) {
542 ((int*)array.data)[i]= ((i%2==0)?-1:1) * ((int) i);
543 ((int*)expected.data)[i] = (-30+2*i) - (i > 15 ? 1 : 0);
544 }
546 /* dummy third argument to trigger a possible fallback for qsort_s */
547 ucx_array_sort(array, ucx_cmp_int, array.data);
548 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL),
549 "failed for bigger arrays");
550 UCX_TEST_END
552 ucx_array_destroy(&expected);
553 ucx_array_destroy(&array);
554 }
556 UCX_TEST(test_ucx_array_autogrow) {
557 int *elems;
558 UcxArray array = ucx_array_new(4, sizeof(int));
559 array.size = 3;
560 elems = array.data;
561 elems[0] = 47;
562 elems[1] = 11;
563 int x = 5;
565 UCX_TEST_BEGIN
567 void* oldptr = array.data;
569 ucx_array_append(&array, 5);
570 UCX_TEST_ASSERT(array.capacity == 4 && array.data == oldptr,
571 "array should not grow too early");
572 ucx_array_append(&array, 5);
573 elems = array.data;
574 UCX_TEST_ASSERT(array.capacity == 8, "array did not grow");
575 UCX_TEST_ASSERT(array.size == 5, "incorrect size after grow");
576 UCX_TEST_ASSERT(elems[3] == 5 && elems[4] == 5, "corrupt data");
578 UCX_TEST_END
579 ucx_array_destroy(&array);
580 }
582 UCX_TEST(test_ucx_array_shrink) {
583 UcxArray array = ucx_array_new(16, sizeof(int));
584 array.size = 4;
586 UCX_TEST_BEGIN
587 UCX_TEST_ASSERT(!ucx_array_shrink(&array), "failed");
588 UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after shrink");
589 UCX_TEST_END
590 ucx_array_destroy(&array);
591 }
593 UCX_TEST(test_ucx_array_resize) {
594 UcxArray array = ucx_array_new(16, sizeof(int));
595 array.size = 8;
597 UCX_TEST_BEGIN
599 UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed");
600 UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after resize");
601 UCX_TEST_ASSERT(array.size == 8, "incorrect size after resize");
603 UCX_TEST_ASSERT(!ucx_array_resize(&array, 4), "failed");
604 UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after resize");
605 UCX_TEST_ASSERT(array.size == 4, "incorrect size after resize");
607 UCX_TEST_END
608 ucx_array_destroy(&array);
609 }
611 UCX_TEST(test_ucx_array_reserve) {
612 UcxArray array = ucx_array_new(16, sizeof(int));
614 UCX_TEST_BEGIN
616 UCX_TEST_ASSERT(!ucx_array_reserve(&array, 4), "failed");
617 UCX_TEST_ASSERT(array.capacity == 16, "reserve shall not shrink");
619 UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed");
620 UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after reserve");
622 UCX_TEST_END
623 ucx_array_destroy(&array);
624 }
626 UCX_TEST(test_ucx_array_util_set) {
627 size_t capacity = 16;
628 int* array = malloc(sizeof(int)*capacity);
630 UCX_TEST_BEGIN
632 UCX_ARRAY_UTIL_SET(&array, &capacity, 7, 42);
634 UCX_TEST_ASSERT(array[7] == 42, "failed");
635 UCX_TEST_ASSERT(capacity == 16, "capacity changed unnecessarily");
637 UCX_ARRAY_UTIL_SET(&array, &capacity, 37, 13);
638 UCX_ARRAY_UTIL_SET(&array, &capacity, 38, 37);
640 UCX_TEST_ASSERT(array[37] == 13, "failed");
641 UCX_TEST_ASSERT(array[38] == 37, "failed");
642 UCX_TEST_ASSERT(capacity == 64, "capacity not grown");
644 UCX_TEST_END
646 free(array);
647 }