diff -r bc8b7c5f55fb -r cd418898af5c tests/test_list.c --- a/tests/test_list.c Thu Oct 31 14:39:05 2024 +0100 +++ b/tests/test_list.c Thu Oct 31 14:54:44 2024 +0100 @@ -29,7 +29,6 @@ #include "cx/test.h" #include "util_allocator.h" #include "cx/compare.h" -#include "cx/utils.h" #include "cx/array_list.h" #include "cx/linked_list.h" @@ -154,7 +153,7 @@ }; CX_TEST_DO { - cx_for_n(i, 18) { + for (size_t i = 0; i < 18; i++) { CX_TEST_ASSERT(i == cx_array_binary_search(array, 18, sizeof(int), &array[i], cx_cmp_int)); } @@ -1225,7 +1224,7 @@ static inline int *int_test_data_added_to_list(CxList *list, bool isptrlist, size_t len) { int *testdata = int_test_data(len); if (isptrlist) { - cx_for_n(i, len) { + for (size_t i = 0; i < len; i++) { cxListAdd(list, &testdata[i]); } } else { @@ -1237,14 +1236,24 @@ roll_out_test_combos(add, { const size_t len = 250; int *testdata = int_test_data(len); - cx_for_n (i, len) CX_TEST_ASSERT(cxListAdd(list, &testdata[i]) == 0); + for (size_t i = 0; i < len; i++) { + CX_TEST_ASSERT(cxListAdd(list, &testdata[i]) == 0); + } CX_TEST_ASSERT(cxListSize(list) == len); - cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]); - cx_for_n (i, len) ++testdata[i]; + for (size_t i = 0; i < len; i++) { + CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]); + } + for (size_t i = 0; i < len; i++) { + ++testdata[i]; + } if (isptrlist) { - cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]); + for (size_t i = 0; i < len; i++) { + CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]); + } } else { - cx_for_n (i, len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i] - 1); + for (size_t i = 0; i < len; i++) { + CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i] - 1); + } } free(testdata); }) @@ -1275,7 +1284,7 @@ int b[5] = array_init(9, 18, 72, 50, 7); int *aptr[5]; int *bptr[5]; - cx_for_n(i, 5) { + for (size_t i = 0; i < 5; i++) { aptr[i] = &a[i]; bptr[i] = &b[i]; } @@ -1322,8 +1331,7 @@ int d8 = 90; int *d6ptr[6]; int *d7ptr[6]; - cx_for_n(i, 6) - { + for (size_t i = 0; i < 6; i++) { d6ptr[i] = &d6a[i]; d7ptr[i] = &d7a[i]; } @@ -1353,8 +1361,7 @@ CX_TEST_ASSERT(0 == cxListInsertSorted(list, &d8)); CX_TEST_ASSERT(cxListSize(list) == 18); - cx_for_n(i, 18) - { + for (size_t i = 0; i < 18; i++) { CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]); } }) @@ -1493,7 +1500,7 @@ size_t len = 128; int *testdata = int_test_data_added_to_list(list, isptrlist, 128); CX_TEST_ASSERT(cxListSize(list) == len); - cx_for_n (i, len) { + for (size_t i = 0; i < len; i++) { CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[i]); } CX_TEST_ASSERT(cxListAt(list, cxListSize(list)) == NULL); @@ -1504,7 +1511,7 @@ int original[16] = array_init(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); int swapped[16] = array_init(8, 4, 14, 3, 1, 5, 9, 12, 0, 6, 11, 10, 7, 15, 2, 13); - cx_for_n(i, 16) { + for (size_t i = 0; i < 16; i++) { cxListAdd(list, &original[i]); } @@ -1548,7 +1555,7 @@ const size_t testdata_len = 500; int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len); - cx_for_n (attempt, 25) { + for (size_t attempt = 0; attempt < 25; attempt++) { int exp = rand() % testdata_len; // NOLINT(cert-msc50-cpp) int val = testdata[exp]; // randomly picked number could occur earlier in list - find first position @@ -1575,7 +1582,9 @@ qsort(expected, testdata_len, sizeof(int), cx_cmp_int); cxListSort(list); - cx_for_n (i, testdata_len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]); + for (size_t i = 0; i < testdata_len; i++) { + CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]); + } free(expected); free(testdata); @@ -1585,7 +1594,7 @@ const size_t testdata_len = 50; int *testdata = int_test_data_added_to_list(list, isptrlist, testdata_len); cxListReverse(list); - cx_for_n(i, testdata_len) { + for (size_t i = 0; i < testdata_len; i++) { CX_TEST_ASSERT(*(int *) cxListAt(list, i) == testdata[testdata_len - 1 - i]); } free(testdata); @@ -1637,14 +1646,18 @@ } CX_TEST_ASSERT(i == 0); CX_TEST_ASSERT(cxListSize(list) == len / 2); - cx_for_n(k, len / 2) CX_TEST_ASSERT(*(int *) cxListAt(list, k) == testdata[k * 2]); + for (size_t k = 0; k < len / 2; k++) { + CX_TEST_ASSERT(*(int *) cxListAt(list, k) == testdata[k * 2]); + } free(testdata); }) roll_out_test_combos(insert_with_iterator, { int fivenums[] = array_init(0, 1, 2, 3, 4); - cx_for_n(i, 5) cxListAdd(list, &fivenums[i]); + for (size_t i = 0; i < 5; i++) { + cxListAdd(list, &fivenums[i]); + } int newdata[] = array_init(10, 20, 30, 40, 50); CxIterator iter = cxListMutIteratorAt(list, 2); @@ -1681,7 +1694,9 @@ CX_TEST_ASSERT(iter.elem_count == 10); int expdata[] = array_init(30, 0, 1, 20, 2, 10, 3, 4, 40, 50); - cx_for_n (j, 10) CX_TEST_ASSERT(*(int *) cxListAt(list, j) == expdata[j]); + for (size_t j = 0; j < 10; j++) { + CX_TEST_ASSERT(*(int *) cxListAt(list, j) == expdata[j]); + } }) static CX_TEST_SUBROUTINE(test_list_verify_compare, CxList *left, CxList *right) { @@ -1709,7 +1724,7 @@ const size_t len = 47; \ int *testdata = int_test_data_added_to_list(list, isptrlist, len); \ CxList *other = otherctr; \ - cx_for_n(i, len) cxListAdd(other, &testdata[i]); \ + for (size_t i = 0; i < len; i++) cxListAdd(other, &testdata[i]); \ CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); \ cxListDestroy(other); \ free(testdata); \ @@ -1732,17 +1747,14 @@ ) roll_out_test_combos_with_defaulted_funcs(compare_unoptimized, { - \ - const size_t len = 33; \ - int *testdata = int_test_data_added_to_list(list, isptrlist, len); \ - CxList *other = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 50); \ - do_set_default_class_funcs(other); \ - cx_for_n(i, len) - cxListAdd(other, &testdata[i]); \ - CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); \ - cxListDestroy(other); \ - free(testdata); \ - + const size_t len = 33; + int *testdata = int_test_data_added_to_list(list, isptrlist, len); + CxList *other = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, sizeof(int), 50); + do_set_default_class_funcs(other); + for (size_t i = 0; i < len; i++) cxListAdd(other, &testdata[i]); + CX_TEST_CALL_SUBROUTINE(test_list_verify_compare, list, other); + cxListDestroy(other); + free(testdata); }) static unsigned destr_test_ctr;