aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/dynarray.c2
-rw-r--r--tests/linked_list.c36
2 files changed, 25 insertions, 13 deletions
diff --git a/tests/dynarray.c b/tests/dynarray.c
index 2d9ea61..3312234 100644
--- a/tests/dynarray.c
+++ b/tests/dynarray.c
@@ -29,7 +29,7 @@ void print_arr(TEST_TYPE *a, int line, const char* message)
#elif defined(TT_LONG)
printf("%li, ", a[i]);
#else
-#pragma message error "PROVIDE A VALID SIGNED INTEGRAL TYPE"
+#pragma error "PROVIDE A VALID SIGNED INTEGRAL TYPE"
#endif
}
printf("} size: %ld, cap: %ld, element_size: %ld\n",
diff --git a/tests/linked_list.c b/tests/linked_list.c
index 93c5f64..1682375 100644
--- a/tests/linked_list.c
+++ b/tests/linked_list.c
@@ -5,6 +5,7 @@
void print_linked_list(struct linked_list* list) {
int i = 0;
printf("linked list at %p, size = %zu\n", list, list->meta.assumed_size);
+ printf("first=%p, last=%p\n", list->first, list->last);
for (struct linked_list_node* current = list->first; current != NULL; current = current->next) {
printf("[%i] = {%i, %p}\n", i, *(int*)current->data, current->next);
++i;
@@ -12,24 +13,35 @@ void print_linked_list(struct linked_list* list) {
}
int main() {
- struct linked_list list = ll_create(sizeof(int));
- int a = 10;
- ll_insert_at(&list, &a, 0);
- a = 11;
- ll_insert_at(&list, &a, 0);
- a = 14;
- ll_insert_at(&list, &a, 2);
- ll_insert_at(&list, &a, 3);
- ll_insert_at(&list, &a, 1);
+ int buf[] = {0, 1, 3, 2, 7, 8, 6, 0, 18, 1};
+ struct linked_list list = ll_create_from_buffer(sizeof(int), buf, sizeof(buf)/sizeof(*buf));
+ ll_sort(&list, __default_int_cmp);
+
+ ll_remove_front(&list);
+ const int one = 1;
+ ll_insert_front(&list, &one);
+ ll_insert_front(&list, &one);
+ ll_append(&list, &one);
+ ll_append(&list, &one);
+ ll_remove_all(&list, &one, __default_int_cmp);
print_linked_list(&list);
+ ll_remove_at(&list, 3);
ll_remove_back(&list);
ll_remove_front(&list);
+ struct linked_list list_2 = ll_deep_copy(&list, NULL);
print_linked_list(&list);
- ll_remove_at(&list, 1);
- ll_remove_at(&list, 0);
- ll_remove_at(&list, 0);
+ print_linked_list(&list_2);
+
+ while (list.first != NULL && list.last != NULL) ll_remove_front(&list);
+ while (list_2.first != NULL && list_2.last != NULL) ll_remove_back(&list_2);
+
print_linked_list(&list);
+ print_linked_list(&list_2);
+
+ if (list.meta.assumed_size != 0 || list_2.meta.assumed_size != 0) return 1;
+
ll_free(&list);
+ ll_free(&list_2);
return 0;
}