summaryrefslogtreecommitdiff
path: root/lichen.test.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2025-10-24 15:31:04 -0500
committersanine <sanine.not@pm.me>2025-10-24 15:31:04 -0500
commitb5c5579402d442de131746b7086c8248bc188205 (patch)
treef646dcd774ce751092e901aa76cc120ffcf3c205 /lichen.test.c
parent9d35ddb703d7ba22bdd6cdbaaf3b5c992ec79025 (diff)
add failing sort testlichen-c
Diffstat (limited to 'lichen.test.c')
-rw-r--r--lichen.test.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lichen.test.c b/lichen.test.c
index 946e0be..6329992 100644
--- a/lichen.test.c
+++ b/lichen.test.c
@@ -175,6 +175,30 @@ LILY_TEST("copy a list") {
#include LILY_PUSH_TEST()
+int compare_data(void *va, void *vb) {
+ int a = *((int*)va);
+ int b = *((int*)vb);
+ return a - b;
+}
+LILY_TEST("sort a list") {
+ li_ll_t *list = li_alloc_ll();
+ int arr[] = { 5, 6, 3, 2, 9, 8, 1, 0, 4, 7 };
+ for (size_t i=0; i<sizeof(arr)/sizeof(int); i++) {
+ li_ll_append(list, arr+i);
+ }
+ li_sort_list(list, compare_data);
+ li_llnode_t *n = list->head;
+ for (size_t i=0; i<sizeof(arr)/sizeof(int); i++) {
+ INFO("[%d] original: %d / sort: %d", i, arr[i], *((int*)n->data));
+ CHECK_EQ((int)i, *((int*)n->data), "%d");
+ n = n->next;
+ }
+
+ li_free_ll(list, do_nothing);
+}
+#include LILY_PUSH_TEST()
+
+
#define LILY_FILE_END
#include LILY_REGISTER_TESTS()