Commit a194fea9 authored by Chris Müller's avatar Chris Müller

test: test case for lists has its own test file now.

parent 508d6336
......@@ -92,132 +92,10 @@ test_queue(const_pointer data)
}
static void
test_list_prepend_and_append(const_pointer data)
{
int items[] = { 1, 2, 3, 4, 5 };
struct CryList* list = cry_list_new();
assert(cry_list_size(list) == 0);
assert(cry_list_head(list) == 0);
assert(cry_list_tail(list) == 0);
// fill linked-lists with items
cry_list_prepend(list, items);
assert(cry_list_size(list) == 1);
assert(cry_list_head(list) == items);
assert(cry_list_tail(list) == items);
cry_list_prepend(list, items + 1);
assert(cry_list_size(list) == 2);
assert(cry_list_head(list) == items + 1);
assert(cry_list_tail(list) == items);
cry_list_append(list, items + 2);
assert(cry_list_size(list) == 3);
assert(cry_list_head(list) == items + 1);
assert(cry_list_tail(list) == items + 2);
cry_list_append(list, items + 3);
assert(cry_list_size(list) == 4);
assert(cry_list_head(list) == items + 1);
assert(cry_list_tail(list) == items + 3);
cry_list_free(list, 0);
}
static void
test_list_iterator(data)
{
int items[] = { 1, 2, 3, 4, 5 };
struct CryList* list = cry_list_new();
cry_list_append(list, items);
cry_list_append(list, items + 1);
cry_list_append(list, items + 2);
cry_list_append(list, items + 3);
cry_list_append(list, items + 4);
struct CryPosition* pos = cry_list_begin(list);
assert(cry_list_prev(pos) == 0);
assert(cry_list_data(pos) == items);
pos = cry_list_next(pos);
assert(cry_list_data(pos) == items + 1);
pos = cry_list_next(pos);
assert(cry_list_data(pos) == items + 2);
pos = cry_list_next(pos);
assert(cry_list_data(pos) == items + 3);
pos = cry_list_next(pos);
assert(cry_list_data(pos) == items + 4);
assert(pos == cry_list_end(list));
assert(cry_list_next(pos) == 0);
cry_list_free(list, 0);
}
static void
test_list_operation(data)
{
int items[] = { 1, 2, 3, 4, 5 };
struct CryList* list = cry_list_new();
cry_list_append(list, items);
cry_list_append(list, items + 1);
cry_list_append(list, items + 2);
cry_list_append(list, items + 3);
cry_list_append(list, items + 4);
assert(cry_list_size(list) == 5);
struct CryPosition* middle = cry_list_index(list, 2);
assert(cry_list_remove(list, middle) == items + 2);
assert(cry_list_size(list) == 4);
struct CryPosition* begin = cry_list_begin(list);
assert(cry_list_data(begin) == items);
assert(cry_list_data(cry_list_step(begin, 1)) == items + 1);
assert(cry_list_data(cry_list_step(begin, 2)) == items + 3);
assert(cry_list_data(cry_list_step(begin, 3)) == items + 4);
assert(cry_list_remove(list, cry_list_begin(list)) == items);
assert(cry_list_remove(list, cry_list_end(list)) == items + 4);
assert(cry_list_size(list) == 2);
cry_list_free(list, 0);
}
static void
test_list(const_pointer data)
{
test_list_prepend_and_append(data);
test_list_iterator(data);
test_list_operation(data);
}
void
cry_test_structures(void)
{
cry_unittest_run("structures.stack", test_stack, 0, 10);
cry_unittest_run("structures.queue", test_queue, 0, 10);
cry_unittest_run("structures.list", test_list, 0, 10);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment