aboutsummaryrefslogtreecommitdiffstats
path: root/tests/linked_list.c
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov2070@gmail.com>2024-06-26 22:21:04 +0300
committerjustanothercatgirl <sotov2070@gmail.com>2024-06-26 22:21:04 +0300
commit28bb6070e64f25aa6ff64f81b59a7f52e12d4092 (patch)
treec5ceaef26d2ce4c48d926e86257e7d186f680448 /tests/linked_list.c
parentf34d8be861231709fc9e115ede326de80c176395 (diff)
Finished and kind of tested linked list
HASH MAP IS "finished" BUT UNTESTED AT ALL, I WILL TEST AND WORK ON IT TOMORROW
Diffstat (limited to 'tests/linked_list.c')
-rw-r--r--tests/linked_list.c36
1 files changed, 24 insertions, 12 deletions
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;
}