From 3a6d7fdfcfe7fe1fa1c09788287e1b005a85a71e Mon Sep 17 00:00:00 2001 From: Blake Romero Date: Mon, 13 Oct 2025 23:21:54 +0100 Subject: Updated list tests & refactored code --- test/test_list.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 9 deletions(-) (limited to 'test/test_list.c') diff --git a/test/test_list.c b/test/test_list.c index d5d5123..1475258 100644 --- a/test/test_list.c +++ b/test/test_list.c @@ -1,4 +1,5 @@ #include +#include #include "../src/lib/list.h" Node* head = NULL; @@ -17,7 +18,7 @@ void teardown() { TestSuite(list, .init=setup, .fini=teardown); // Node -Test(list,init) { +Test(list, init) { int val = 17; head = node_init(val); cr_expect(head != NULL); @@ -25,33 +26,82 @@ Test(list,init) { } // Length -Test(list,length) { +Test(list, length) { cr_expect(list_length(head) == 1); } // Push -Test(list,push) { +Test(list, push) { int val = 12; list_push(&head,val); - cr_expect(head->next != NULL); cr_expect(head->value == val); + cr_expect(head->next != NULL); } // Pop -Test(list,pop) { +Test(list, pop) { int val = list_pop(&head); cr_expect(val == 7); cr_expect(list_length(head) == 0); } +// Get +Test(list, get) { + int value = 7; + int result = list_get(head,0); + cr_expect(result == value, + "Error: Result '%i' did not match expect value '%i'.", + result, value); +} + // Append -// ... +Test(list, append) { + int value=10; + list_append(&head, value); + int result = list_get(head,1); + cr_expect(result == value, + "Error: Result '%i' did not match expect value '%i'.", + result, value); +} // Insert -// ... +Test(list, insert) { + list_push(&head, 22); + list_push(&head, 44); + list_push(&head, 55); + int value = 33, pos = 2; + list_insert(&head, value, pos); + int result = list_get(head, pos); + cr_expect(result == value, + "Error: Result '%i' did not match expect value '%i'.", + result, value); +} // Remove -// ... +Test(list, remove) { + list_push(&head, 22); + list_push(&head, 44); + list_push(&head, 55); + list_rm(&head, 2); + int result = list_get(head, 2); + cr_expect(result != 22, + "Error: Result '%i' did not match expected value.", + result); +} + +Test(list, set) { + int value = 8, index = 1; + list_push(&head, 5); + list_push(&head, 9); + list_set(head, index, value); + int result = list_get(head, index); + cr_expect(result == value, + "Error: Result '%i' did not match expected value '%i'.", + result, value); +} // Free -// ... +Test(list, free) { + list_free(&head); + cr_expect(head == NULL); +} -- cgit