diff -r 68754c7de906 -r 38fa7e41194c tests/test_list.c --- a/tests/test_list.c Thu Nov 07 22:46:58 2024 +0100 +++ b/tests/test_list.c Mon Nov 11 21:42:14 2024 +0100 @@ -36,66 +36,41 @@ #include CX_TEST(test_array_add) { - int stackspace[5] = {1,1,2,3,5}; - int *stackarray = stackspace; - size_t stackarray_size = 3; - size_t stackarray_capacity = 5; - CX_ARRAY_DECLARE(int, heaparray); - heaparray = calloc(5, sizeof(int)); - heaparray[0] = 2; - heaparray[1] = 3; - heaparray[2] = 5; - heaparray[3] = 7; - heaparray[4] = 11; - heaparray_size = 3; - heaparray_capacity = 5; + CX_ARRAY_DECLARE(int, arr); + arr = calloc(5, sizeof(int)); + arr[0] = 2; + arr[1] = 3; + arr[2] = 5; + arr[3] = 7; + arr[4] = 11; + arr_size = 3; + arr_capacity = 5; int elem = 8, elem2 = 47; - enum cx_array_result result; + int result; CX_TEST_DO { - result = cx_array_add(&stackarray, &stackarray_size, &stackarray_capacity, sizeof(int), &elem, NULL); - CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS); - CX_TEST_ASSERT(stackarray[0] == 1); - CX_TEST_ASSERT(stackarray[1] == 1); - CX_TEST_ASSERT(stackarray[2] == 2); - CX_TEST_ASSERT(stackarray[3] == 8); - CX_TEST_ASSERT(stackarray[4] == 5); - CX_TEST_ASSERT(stackarray_size == 4); - CX_TEST_ASSERT(stackarray_capacity == 5); + result = cx_array_simple_add(arr, elem); + CX_TEST_ASSERT(result == 0); + CX_TEST_ASSERT(arr[0] == 2); + CX_TEST_ASSERT(arr[1] == 3); + CX_TEST_ASSERT(arr[2] == 5); + CX_TEST_ASSERT(arr[3] == 8); + CX_TEST_ASSERT(arr[4] == 11); + CX_TEST_ASSERT(arr_size == 4); + CX_TEST_ASSERT(arr_capacity == 5); - stackarray_size = 5; - result = cx_array_add(&stackarray, &stackarray_size, &stackarray_capacity, sizeof(int), &elem2, NULL); - CX_TEST_ASSERT(result == CX_ARRAY_REALLOC_NOT_SUPPORTED); - CX_TEST_ASSERT(stackarray[0] == 1); - CX_TEST_ASSERT(stackarray[1] == 1); - CX_TEST_ASSERT(stackarray[2] == 2); - CX_TEST_ASSERT(stackarray[3] == 8); - CX_TEST_ASSERT(stackarray[4] == 5); - CX_TEST_ASSERT(stackarray_size == 5); - CX_TEST_ASSERT(stackarray_capacity == 5); - - result = cx_array_simple_add(heaparray, elem); - CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS); - CX_TEST_ASSERT(heaparray[0] == 2); - CX_TEST_ASSERT(heaparray[1] == 3); - CX_TEST_ASSERT(heaparray[2] == 5); - CX_TEST_ASSERT(heaparray[3] == 8); - CX_TEST_ASSERT(heaparray[4] == 11); - CX_TEST_ASSERT(heaparray_size == 4); - CX_TEST_ASSERT(heaparray_capacity == 5); - - heaparray_size = 5; - result = cx_array_simple_add(heaparray, elem2); - CX_TEST_ASSERT(result == CX_ARRAY_SUCCESS); - CX_TEST_ASSERT(heaparray[0] == 2); - CX_TEST_ASSERT(heaparray[1] == 3); - CX_TEST_ASSERT(heaparray[2] == 5); - CX_TEST_ASSERT(heaparray[3] == 8); - CX_TEST_ASSERT(heaparray[4] == 11); - CX_TEST_ASSERT(heaparray[5] == 47); - CX_TEST_ASSERT(heaparray_size == 6); - CX_TEST_ASSERT(heaparray_capacity >= 6); + arr_size = 5; + result = cx_array_simple_add(arr, elem2); + CX_TEST_ASSERT(result == 0); + CX_TEST_ASSERT(arr[0] == 2); + CX_TEST_ASSERT(arr[1] == 3); + CX_TEST_ASSERT(arr[2] == 5); + CX_TEST_ASSERT(arr[3] == 8); + CX_TEST_ASSERT(arr[4] == 11); + CX_TEST_ASSERT(arr[5] == 47); + CX_TEST_ASSERT(arr_size == 6); + CX_TEST_ASSERT(arr_capacity >= 6); } - free(heaparray); + free(arr); } CX_TEST(test_array_insert_sorted) {