#include #include #include "../src/lib/list.h" Node* head = NULL; // Run on every test void setup() { head = node_init(7); } // Run after every test void teardown() { list_free(&head); } // Configure test suite TestSuite(list, .init=setup, .fini=teardown); // Node Test(list, init) { int val = 17; head = node_init(val); cr_expect(head != NULL); cr_expect(head->value == val); } // Length Test(list, length) { cr_expect(list_length(head) == 1); } // Push Test(list, push) { int val = 12; list_push(&head,val); cr_expect(head->value == val); cr_expect(head->next != NULL); } // 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); }