Initial commit

This commit is contained in:
Phireh 2025-01-06 19:39:32 +01:00
commit f30f7a6449
10 changed files with 1126 additions and 0 deletions

90
tests.c Normal file
View file

@ -0,0 +1,90 @@
#include "ihct/ihct.h"
#include "list.h"
TEST(node_create)
{
node_t node = { INT, { .vi = -1 }, 0 };
ASSERT(node.type == INT && node.vi == -1);
}
TEST(list_create)
{
node_t head = { INT, { .vi = 1 }, 0 };
node_t n = { INT, { .vi = 2 }, 0 };
list_append(&head, &n);
ASSERT(head.next == &n);
}
TEST(list_query)
{
node_t n0 = { INT, { .vi = 1 }, 0 };
node_t n1 = { INT, { .vi = 2 }, 0 };
node_t n2 = { INT, { .vi = 3 }, 0 };
list_append(&n0, &n1);
list_append(&n0, &n2);
ASSERT(list_nth(&n0, 1) == &n1);
}
TEST(list_delete)
{
node_t n0 = { INT, { .vi = 1 }, 0 };
node_t n1 = { INT, { .vi = 2 }, 0 };
node_t n2 = { INT, { .vi = 3 }, 0 };
list_append(&n0, &n1);
list_append(&n0, &n2);
list_delete_nth(&n0, 1);
ASSERT(list_nth(&n0, 1) == &n2);
}
TEST(dlist_size)
{
dnode_t n0 = { INT, { .vi = 1 }, 0, 0 };
dnode_t n1 = { INT, { .vi = 2 }, 0, 0 };
dnode_t n2 = { INT, { .vi = 3 }, 0, 0 };
dlist_append(&n0, &n1);
dlist_append(&n1, &n2);
//list_delete_nth(&n0, 1);
ASSERT(dlist_size(&n0) == 3);
ASSERT(dlist_size(&n0) == 3);
}
TEST(dlist_nth)
{
dnode_t n0 = { INT, { .vi = 1 }, 0, 0 };
dnode_t n1 = { INT, { .vi = 1 }, 0, 0 };
dnode_t n2 = { INT, { .vi = 1 }, 0, 0 };
dnode_t n3 = { INT, { .vi = 1 }, 0, 0 };
dlist_append(&n0, &n1);
dlist_append(&n1, &n2);
dlist_append(&n2, &n3);
ASSERT(dlist_nth(1, &n0, 0, 0) == &n1);
ASSERT(dlist_nth(1, &n0, &n3, 4) == &n1);
ASSERT(dlist_nth(2, &n0, 0, 0) == &n2);
ASSERT(dlist_nth(2, &n0, &n3, 4) == &n2);
ASSERT(dlist_nth(0, &n0, 0, 0) == &n0);
ASSERT(dlist_nth(3, &n0, &n3, 4) == &n3);
ASSERT(!dlist_nth(4, &n0, &n3, 4));
}
TEST(dlist_nth_circular_and_is_circular)
{
dnode_t n0 = { INT, { .vi = 0 }, 0, 0 };
dnode_t n1 = { INT, { .vi = 1 }, 0, 0 };
dnode_t n2 = { INT, { .vi = 2 }, 0, 0 };
dnode_t n3 = { INT, { .vi = 3 }, 0, 0 };
dnode_t n4 = { INT, { .vi = 4 }, 0, 0 };
dlist_append(&n0, &n1);
dlist_append(&n0, &n2);
dlist_append(&n0, &n3);
dlist_append(&n0, &n4);
dlist_append(&n4, &n0);
ASSERT(dlist_nth_circular(5, &n4) == &n4);
ASSERT(dlist_is_circular(&n0) == 1);
}
int main(int argc, char **argv)
{
return IHCT_RUN(argc, argv);
}