Mon, 20 Dec 2021 12:10:48 +0100
add linked list tests for cxListAt()
test/test_list.c | file | annotate | diff | comparison | revisions |
--- a/test/test_list.c Mon Dec 20 11:58:36 2021 +0100 +++ b/test/test_list.c Mon Dec 20 12:10:48 2021 +0100 @@ -572,6 +572,28 @@ CU_ASSERT_TRUE(cxTestingAllocatorVerify()) } +void test_hl_linked_list_at(void) { + cxTestingAllocatorReset(); + + CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); + + int data; + data = 5; + cxListAdd(list, &data); + data = 47; + cxListAdd(list, &data); + data = 13; + cxListAdd(list, &data); + + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) + CU_ASSERT_PTR_NULL(cxListAt(list, 3)) + + cxLinkedListDestroy(list); + CU_ASSERT_TRUE(cxTestingAllocatorVerify()) +} + void test_hl_linked_list_find(void) { cxTestingAllocatorReset(); @@ -757,6 +779,25 @@ CU_ASSERT_TRUE(cxTestingAllocatorVerify()) } +void test_hl_ptr_linked_list_at(void) { + cxTestingAllocatorReset(); + + CxList list = cxPointerLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int); + + int a = 5, b = 47, c = 13; + cxListAdd(list, &a); + cxListAdd(list, &b); + cxListAdd(list, &c); + + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) + CU_ASSERT_PTR_NULL(cxListAt(list, 3)) + + cxLinkedListDestroy(list); + CU_ASSERT_TRUE(cxTestingAllocatorVerify()) +} + void test_hl_ptr_linked_list_find(void) { cxTestingAllocatorReset(); @@ -849,6 +890,7 @@ cu_add_test(suite, test_hl_linked_list_add); cu_add_test(suite, test_hl_linked_list_insert); cu_add_test(suite, test_hl_linked_list_remove); + cu_add_test(suite, test_hl_linked_list_at); cu_add_test(suite, test_hl_linked_list_find); cu_add_test(suite, test_hl_linked_list_sort); @@ -858,6 +900,7 @@ cu_add_test(suite, test_hl_ptr_linked_list_add); cu_add_test(suite, test_hl_ptr_linked_list_insert); cu_add_test(suite, test_hl_ptr_linked_list_remove); + cu_add_test(suite, test_hl_ptr_linked_list_at); cu_add_test(suite, test_hl_ptr_linked_list_find); cu_add_test(suite, test_hl_ptr_linked_list_sort);