diff options
| author | Mistivia <i@mistivia.com> | 2025-06-16 19:28:28 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-06-16 19:28:28 +0800 |
| commit | e3bc104f9b3df0649d2a5b1ac9b110b3729ffdbf (patch) | |
| tree | 76f4344a890fc4c872ac1ab92688072ffb66dfee /tests/test_list.c | |
| parent | d614ec90581e504b9888d2ed66c20a8a86fbc8b2 (diff) | |
add list test
Diffstat (limited to 'tests/test_list.c')
| -rw-r--r-- | tests/test_list.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_list.c b/tests/test_list.c new file mode 100644 index 0000000..e9ff5e8 --- /dev/null +++ b/tests/test_list.c @@ -0,0 +1,44 @@ +#include "list.h" + +#include <assert.h> +#include <stdio.h> + +int main() { + printf("[TEST] list\n"); + + IntList lst; + IntList_init(&lst); + + IntList_push_back(&lst, 3); + IntList_push_front(&lst, 1); + IntList_insert_after(&lst, IntList_begin(&lst), 2); + + assert(lst.vhead->next->val == 1); + assert(lst.vhead->next->next->val == 2); + assert(lst.vhead->next->next->next->val == 3); + + assert(lst.vtail->prev->val == 3); + assert(lst.vtail->prev->prev->val == 2); + assert(lst.vtail->prev->prev->prev->val == 1); + + assert(IntList_len(&lst) == 3); + assert(IntList_last(&lst)->val == 3); + assert(IntList_begin(&lst)->val == 1); + assert(IntList_end(&lst) == lst.vtail); + + IntList_pop_back(&lst); + assert(lst.vhead->next->val == 1); + assert(lst.vhead->next->next->val == 2); + assert(lst.vtail->prev->val == 2); + assert(lst.vtail->prev->prev->val == 1); + + IntList_pop_front(&lst); + assert(lst.vhead->next->val == 2); + assert(lst.vtail->prev->val == 2); + + assert(IntList_len(&lst) == 1); + + IntList_free(&lst); + + printf("[PASS] list\n"); +} |
