diff -r 872ae61c8945 -r 6d7aa8a1a3b3 test/array_tests.c --- a/test/array_tests.c Thu Jul 04 21:31:45 2019 +0200 +++ b/test/array_tests.c Thu Jul 04 22:23:15 2019 +0200 @@ -151,19 +151,17 @@ UCX_TEST_BEGIN - UCX_TEST_ASSERT(ucx_array_equals(a1, a2, ucx_cmp_int, NULL) == 0, "failed"); - UCX_TEST_ASSERT(ucx_array_equals(a1, a4, ucx_cmp_int, NULL) > 0, "failed"); - UCX_TEST_ASSERT(ucx_array_equals(a4, a1, ucx_cmp_int, NULL) < 0, "failed"); - UCX_TEST_ASSERT(ucx_array_equals(a1, a3, ucx_cmp_int, NULL) < 0, - "comparing arrays of different element size failed"); - UCX_TEST_ASSERT(ucx_array_equals(a3, a1, ucx_cmp_int, NULL) > 0, - "comparing arrays of different element size failed"); + UCX_TEST_ASSERT(ucx_array_equals(a1, a2, ucx_cmp_int, NULL), "failed"); + UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, ucx_cmp_int, NULL), "failed"); + UCX_TEST_ASSERT(!ucx_array_equals(a4, a1, ucx_cmp_int, NULL), "failed"); + UCX_TEST_ASSERT(!ucx_array_equals(a1, a3, ucx_cmp_int, NULL), + "comparing arrays of different element size shall fail"); + UCX_TEST_ASSERT(!ucx_array_equals(a3, a1, ucx_cmp_int, NULL), + "comparing arrays of different element size shall fail"); - UCX_TEST_ASSERT(ucx_array_equals(a1, a2, NULL, NULL) == 0, + UCX_TEST_ASSERT(ucx_array_equals(a1, a2, NULL, NULL), "compare using memcmp() failed"); - UCX_TEST_ASSERT(ucx_array_equals(a1, a4, NULL, NULL) > 0, - "compare using memcmp() failed"); - UCX_TEST_ASSERT(ucx_array_equals(a4, a1, NULL, NULL) < 0, + UCX_TEST_ASSERT(!ucx_array_equals(a1, a4, NULL, NULL), "compare using memcmp() failed"); UCX_TEST_END @@ -337,11 +335,11 @@ UCX_TEST_BEGIN UCX_TEST_ASSERT(array.data != copy.data, "no true copy"); - UCX_TEST_ASSERT(ucx_array_equals(array, copy, ucx_cmp_int, NULL), "failed"); UCX_TEST_ASSERT(array.size == copy.size, "size mismatch"); UCX_TEST_ASSERT(array.capacity == copy.capacity, "capacity mismatch"); UCX_TEST_ASSERT(array.elemsize == copy.elemsize, "element size mismatch"); UCX_TEST_ASSERT(array.allocator == copy.allocator, "allocator mismatch"); + UCX_TEST_ASSERT(ucx_array_equals(array, copy, ucx_cmp_int, NULL), "failed"); UCX_TEST_END @@ -369,10 +367,22 @@ UCX_TEST_BEGIN void* original_ptr = array.data; - UCX_TEST_ASSERT(!ucx_array_sort(array, ucx_cmp_int, NULL), "failed"); - UCX_TEST_ASSERT(!ucx_array_equals(array, expected, NULL, NULL), "failed"); + ucx_array_sort(array, ucx_cmp_int, NULL); + UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed"); UCX_TEST_ASSERT(array.size == 5, "size corrupted"); UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate"); + + ucx_array_reserve(&array, 32); + ucx_array_reserve(&expected, 32); + array.size = expected.size = 32; + for (size_t i = 0 ; i < 32 ; i++) { + ucx_array_at_int(array, i) = ((i%2==0)?-1:1) * ((int) i); + ucx_array_at_int(expected, i) = (-30+2*i) - (i > 15 ? 1 : 0); + } + + ucx_array_sort(array, ucx_cmp_int, NULL); + UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), + "failed for bigger arrays"); UCX_TEST_END ucx_array_free(&expected);