Skip to content

Commit

Permalink
List tests cleaned up.
Browse files Browse the repository at this point in the history
  • Loading branch information
zedshaw committed Mar 4, 2012
1 parent e98e390 commit 428a87c
Showing 1 changed file with 33 additions and 52 deletions.
85 changes: 33 additions & 52 deletions tests/list_tests.c
Expand Up @@ -2,29 +2,32 @@
#include <lcthw/list.h>
#include <assert.h>

char *test_create_destroy()
static List *list = NULL;
char *test1 = "test1 data";
char *test2 = "test2 data";
char *test3 = "test3 data";


char *test_create()
{
List *list = List_create();
list = List_create();
mu_assert(list != NULL, "Failed to create list.");

List_clear(list); // should do nothing
List_destroy(list);
return NULL;
}

list = List_create();
mu_assert(list != NULL, "Failed to make list #2");

char *test_destroy()
{
List_clear_destroy(list);

return NULL;

}


char *test_push_pop()
{
List *list = List_create();
mu_assert(list != NULL, "Failed to create test list.");
char *test1 = "test1 data";
char *test2 = "test2 data";
char *test3 = "test3 data";

List_push(list, test1);
mu_assert(List_last(list) == test1, "Wrong last value.");

Expand All @@ -45,19 +48,11 @@ char *test_push_pop()
mu_assert(val == test1, "Wrong value on pop.");
mu_assert(List_count(list) == 0, "Wrong count after pop.");

List_destroy(list);

return NULL;
}

char *test_shift_unshift()
char *test_shift()
{
List *list = List_create();
mu_assert(list != NULL, "Failed to create list.");
char *test1 = "test1 data";
char *test2 = "test2 data";
char *test3 = "test3 data";

List_shift(list, test1);
mu_assert(List_first(list) == test1, "Wrong last value.");

Expand All @@ -68,39 +63,11 @@ char *test_shift_unshift()
mu_assert(List_first(list) == test3, "Wrong last value.");
mu_assert(List_count(list) == 3, "Wrong count on shift.");

char *val = List_unshift(list);
mu_assert(val == test3, "Wrong value on unshift.");

val = List_unshift(list);
mu_assert(val == test2, "Wrong value on unshift.");

val = List_unshift(list);
mu_assert(val == test1, "Wrong value on unshift.");
mu_assert(List_count(list) == 0, "Wrong count after unshift.");

List_destroy(list);

return NULL;
}

char *test_remove()
{
List *list = List_create();
mu_assert(list != NULL, "Failed to create list.");
char *test1 = "test1 data";
char *test2 = "test2 data";
char *test3 = "test3 data";

List_shift(list, test1);
mu_assert(List_first(list) == test1, "Wrong last value.");

List_shift(list, test2);
mu_assert(List_first(list) == test2, "Wrong last value");

List_shift(list, test3);
mu_assert(List_first(list) == test3, "Wrong last value.");
mu_assert(List_count(list) == 3, "Wrong count on shift.");

// we only need to test the middle remove case since push/shift
// already tests the other cases

Expand All @@ -110,19 +77,33 @@ char *test_remove()
mu_assert(List_first(list) == test3, "Wrong first after remove.");
mu_assert(List_last(list) == test1, "Wrong last after remove.");

List_destroy(list);
return NULL;
}


char *test_unshift()
{
char *val = List_unshift(list);
mu_assert(val == test3, "Wrong value on unshift.");

val = List_unshift(list);
mu_assert(val == test1, "Wrong value on unshift.");
mu_assert(List_count(list) == 0, "Wrong count after unshift.");

return NULL;
}



char *all_tests() {
mu_suite_start();

mu_run_test(test_create_destroy);
mu_run_test(test_create);
mu_run_test(test_push_pop);
mu_run_test(test_shift_unshift);
mu_run_test(test_shift);
mu_run_test(test_remove);
mu_run_test(test_unshift);
mu_run_test(test_destroy);

return NULL;
}
Expand Down

0 comments on commit 428a87c

Please sign in to comment.