Implementing ex32 List copy, split, and join
This commit is contained in:
@@ -6,6 +6,7 @@ static List *list = NULL;
|
||||
char *test1 = "test1 data";
|
||||
char *test2 = "test2 data";
|
||||
char *test3 = "test3 data";
|
||||
char *test4 = "test4 data";
|
||||
|
||||
|
||||
char *test_create()
|
||||
@@ -95,6 +96,95 @@ char *test_shift()
|
||||
}
|
||||
|
||||
|
||||
char *test_copy()
|
||||
{
|
||||
list = List_create();
|
||||
|
||||
mu_assert(List_count(list) == 0, "Wrong count before copy.");
|
||||
List_push(list, test1);
|
||||
List_push(list, test2);
|
||||
List_push(list, test3);
|
||||
List_push(list, test4);
|
||||
|
||||
mu_assert(List_count(list) == 4, "Wrong count after push.");
|
||||
|
||||
List *copy = List_copy(list);
|
||||
mu_assert(copy != list, "Copy and list have same address.");
|
||||
mu_assert(List_count(copy) == 4, "Copy has wrong count.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *test_split()
|
||||
{
|
||||
mu_assert(List_count(list) == 4, "Wrong count before split.");
|
||||
|
||||
List *a = List_create();
|
||||
List *b = List_create();
|
||||
List *tmp = List_copy(list);
|
||||
|
||||
int rc = -1;
|
||||
rc = List_split(tmp, test2, a, b);
|
||||
mu_assert(rc == 0, "Failed to split.");
|
||||
mu_assert(List_count(a) == 2, "List 'a' has wrong count.");
|
||||
mu_assert(List_count(b) == 2, "List 'b' has wrong count.");
|
||||
|
||||
List_destroy(a);
|
||||
List_destroy(b);
|
||||
|
||||
a = List_create();
|
||||
b = List_create();
|
||||
tmp = List_copy(list);
|
||||
|
||||
rc = List_split(tmp, test1, a, b);
|
||||
mu_assert(rc == 0, "Failed to split.");
|
||||
mu_assert(List_count(a) == 1, "List 'a' has wrong count.");
|
||||
mu_assert(List_count(b) == 3, "List 'b' has wrong count.");
|
||||
|
||||
List_destroy(a);
|
||||
List_destroy(b);
|
||||
|
||||
a = List_create();
|
||||
b = List_create();
|
||||
tmp = List_copy(list);
|
||||
|
||||
rc = List_split(tmp, test3, a, b);
|
||||
mu_assert(rc == 0, "Failed to split.");
|
||||
mu_assert(List_count(a) == 3, "List 'a' has wrong count.");
|
||||
mu_assert(List_count(b) == 1, "List 'b' has wrong count.");
|
||||
|
||||
List_destroy(a);
|
||||
List_destroy(b);
|
||||
|
||||
a = List_create();
|
||||
b = List_create();
|
||||
tmp = List_copy(list);
|
||||
|
||||
rc = List_split(tmp, test4, a, b);
|
||||
mu_assert(rc == 0, "Failed to split.");
|
||||
mu_assert(List_count(a) == 4, "List 'a' has wrong count.");
|
||||
mu_assert(List_count(b) == 0, "List 'b' has wrong count.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *test_join()
|
||||
{
|
||||
mu_assert(List_count(list) == 4, "Wrong count before join.");
|
||||
|
||||
List *b = List_create();
|
||||
List_push(b, test4);
|
||||
mu_assert(List_count(b) == 1, "List 'b' has wrong count.");
|
||||
|
||||
List_join(list, b);
|
||||
mu_assert(List_count(list) == 5, "Wrong count after join.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *all_tests() {
|
||||
mu_suite_start();
|
||||
@@ -105,6 +195,9 @@ char *all_tests() {
|
||||
mu_run_test(test_remove);
|
||||
mu_run_test(test_shift);
|
||||
mu_run_test(test_destroy);
|
||||
mu_run_test(test_copy);
|
||||
mu_run_test(test_split);
|
||||
mu_run_test(test_join);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user