mirror of
https://github.com/Tilo-K/tstd.git
synced 2026-01-09 14:31:01 +00:00
80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
//
|
|
// Created by tilok on 23.08.2025.
|
|
//
|
|
#include <assert.h>
|
|
|
|
#include "tstd/list.h"
|
|
|
|
DEFINE_LIST(int)
|
|
DEFINE_LIST_PTR(charptr)
|
|
|
|
int test_list_int_create() {
|
|
list_int* list = list_int_create();
|
|
assert(list->capacity == 10);
|
|
|
|
list_int_free(list);
|
|
return 0;
|
|
}
|
|
|
|
int test_list_add_element() {
|
|
list_charptr* list = list_charptr_create();
|
|
list_charptr_add(list, "Hello");
|
|
|
|
assert(list->length == 1);
|
|
assert(strcmp(list->data[0], "Hello") == 0);
|
|
|
|
list_charptr_free(list);
|
|
return 0;
|
|
}
|
|
|
|
int test_add_multiple_elements() {
|
|
list_charptr* list = list_charptr_create();
|
|
for (int i = 0; i < 1000; i++) {
|
|
list_charptr_add(list, "Hello");
|
|
}
|
|
assert(list->length == 1000);
|
|
assert(list->capacity > 1000);
|
|
|
|
list_charptr_free(list);
|
|
return 0;
|
|
}
|
|
|
|
int test_delete_element() {
|
|
list_charptr* list = list_charptr_create();
|
|
list_charptr_add(list, "Hello");
|
|
list_charptr_add(list, "World");
|
|
list_charptr_add(list, "Test");
|
|
list_charptr_delete(list, 1);
|
|
|
|
assert(list->length == 2);
|
|
assert(strcmp(list->data[1], "Test") == 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int test_list_contains() {
|
|
list_charptr* list = list_charptr_create();
|
|
list_charptr_add(list, "Hello");
|
|
list_charptr_add(list, "World");
|
|
list_charptr_add(list, "Test");
|
|
|
|
assert(list_contains(list, "Hello") == 1);
|
|
assert(list_contains(list, "World") == 1);
|
|
assert(list_contains(list, "Test") == 1);
|
|
assert(list_contains(list, "Other") == 0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
int result = 0;
|
|
|
|
result += test_list_int_create();
|
|
result += test_list_add_element();
|
|
result += test_add_multiple_elements();
|
|
result += test_delete_element();
|
|
result += test_list_contains();
|
|
|
|
return result;
|
|
}
|