liblcthw
liblcthw copied to clipboard
Missing a test for List_clear_destroy()
The Problem
Missing a test to check if the code actually worked or not.
https://github.com/zedshaw/liblcthw/blob/1249486dc6c4dfc6bade728423097351698f3f27/tests/list_tests.c#L18-L24
My Approach
Learning from p. 149 "Question Authority". 😉
Using TDD (see attached image), where I first write the test-cases first I stumbled upon a bug in the lists_tests.c file.

The code will not really test if the list has been cleared and destroyed.
The test will PASS by just adding the following minimal implementation function to list.c
void *List_clear_destroy(List *list) {
return (list);
}
Suggested Solution
I suggest adding a test using mu_assert(), to actually test the list variable.
Now I do not know if there is any better way to test this, but at least it is testing something. 😄
char *test_destroy()
{
List_clear_destroy(list);
// Add the following test
mu_assert(list->count == 0, "Failed to clear list");
return NULL;
}
What do you think @zedshaw ?
Do you have a better way to test and check if the list is empty, please let me know because I am very curious about how that could be done.