--- a/test/test_list.c Tue Dec 28 14:16:04 2021 +0100 +++ b/test/test_list.c Tue Dec 28 14:25:05 2021 +0100 @@ -125,6 +125,31 @@ CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 1), &b) } +void test_linked_list_find(void) { + int data[] = {2, 4, 6, 8}; + void *list = create_test_data(4, data); + int s; + + s = 2; + CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data, + false, (CxListComparator) cmp_int, &s), 0) + s = 4; + CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data, + false, (CxListComparator) cmp_int, &s), 1) + s = 6; + CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data, + false, (CxListComparator) cmp_int, &s), 2) + s = 8; + CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data, + false, (CxListComparator) cmp_int, &s), 3) + s = 10; + CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data, + false, (CxListComparator) cmp_int, &s), 4) + s = -2; + CU_ASSERT_EQUAL(cx_linked_list_find(list, loc_next, loc_data, + false, (CxListComparator) cmp_int, &s), 4) +} + void test_linked_list_compare(void) { int a[] = {2, 4, 6, 8}; int b[] = {2, 4, 6}; @@ -135,19 +160,19 @@ void *lc = create_test_data(4, c); CU_ASSERT_TRUE(0 < cx_linked_list_compare(la, lb, loc_next, loc_data, - 0, (CxListComparator) cmp_int) + false, (CxListComparator) cmp_int) ) CU_ASSERT_TRUE(0 > cx_linked_list_compare(lb, la, loc_next, loc_data, - 0, (CxListComparator) cmp_int) + false, (CxListComparator) cmp_int) ) CU_ASSERT_TRUE(0 < cx_linked_list_compare(lc, la, loc_next, loc_data, - 0, (CxListComparator) cmp_int) + false, (CxListComparator) cmp_int) ) CU_ASSERT_TRUE(0 > cx_linked_list_compare(la, lc, loc_next, loc_data, - 0, (CxListComparator) cmp_int) + false, (CxListComparator) cmp_int) ) CU_ASSERT_TRUE(0 == cx_linked_list_compare(la, la, loc_next, loc_data, - 0, (CxListComparator) cmp_int) + false, (CxListComparator) cmp_int) ) destroy_test_data(la); @@ -487,7 +512,7 @@ void *end = cx_linked_list_last(begin, loc_next); cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data, - 0, (CxListComparator) cmp_int); + false, (CxListComparator) cmp_int); struct node *check = begin; struct node *check_last = NULL; @@ -952,6 +977,7 @@ cu_add_test(suite, test_linked_list_link_unlink); cu_add_test(suite, test_linked_list_at); + cu_add_test(suite, test_linked_list_find); cu_add_test(suite, test_linked_list_compare); cu_add_test(suite, test_linked_list_prepend); cu_add_test(suite, test_linked_list_add);