void LL_length_test(int count) { nodePtr head = newTestLL(count); int i = 1; nodePtr n = head; while ((n = n->next)) i++; processTestResults("length: head", LL_length(head) == i); processTestResults("length: NULL", LL_length(NULL) == 0); LL_freeAll(&head); }
char *test_linked_list_length() { int length = LL_length(head); test_assert(length == 4, "Did not get correct length"); return NULL; }
char *test_linked_list_delete() { int length = LL_length(head); // Deleting the last node LL_delete(&head, val3); test_assert(LL_length(head) == (length - 1), "Wrong length after deletion"); struct ll_node *last = LL_last(head); test_assert(last->val != val3, "linked list last node has wrong val after deletion"); // Deleting the head node LL_delete(&head, val4); test_assert(LL_length(head) == (length - 2), "Wrong length after deletion"); test_assert(head->val != val4, "linked list head node has wrong val after deletion"); return NULL; }
void LL_find_test(int count) { nodePtr head = newTestLL(count), indexedN = LL_ofIndex(head, LL_length(head) / 2); LL_value_t indexedNValue = LL_findByValue(head, indexedN->value)->value; processTestResults("find: value in list", indexedNValue == indexedN->value); LL_free(&head, &indexedN); processTestResults("find: value not in list", LL_find(head, indexedN) == NULL); LL_freeAll(&head); }