waitui/tests/library/list/test_list.c
Rick Barenthin 629435626e
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
feat(list): update test and pipeline
2022-05-20 13:41:15 +02:00

79 lines
2.2 KiB
C

/**
* @file test_list.c
* @author rick
* @date 09.07.21
* @brief Test for the List implementation
*/
#include "waitui/list.h"
#include "../../bdd-for-c-ext.h"
typedef struct value {
int count;
int i;
} value;
static value *value_new(int i) {
value *this = calloc(1, sizeof(*this));
if (!this) { return NULL; }
this->i = i;
return this;
}
static void value_destroy(value **this) {
if (!this || !(*this)) { return; }
free(*this);
*this = NULL;
}
CREATE_LIST_TYPE(INTERFACE, value)
CREATE_LIST_TYPE(IMPLEMENTATION, value)
spec("list") {
context("use as a normal list") {
static value_list *list = NULL;
before_each() {
list = value_list_new();
check(list != NULL, "list should not be NULL");
}
after_each() {
value_list_destroy(&list);
check(list == NULL, "list should be NULL");
}
describe("value_list_push()") {
for_it(
"should push values onto the end list and it should be there",
params_format(2, "start: %d", "elements: %d"),
format_args(test_param.start, test_param.count),
{
int start;
int count;
},
test_params(
{0, 0},
{0, 1},
{1, 1},
{4, 20},
)
) {
for (int i = test_param.start; i < test_param.start + test_param.count; ++i) {
check(value_list_push(list, value_new(i)) == 1);
value *value = value_list_peek(list);
check(value->i == i, "value should be %d but is %d", i, value->i);
}
for (int i = test_param.start + test_param.count - 1; i >= test_param.start; --i) {
value *value = value_list_pop(list);
check(value != NULL, "value should not be NULL");
check(value->i == i, "value should be %d but is %d", i, value->i);
value_destroy(&value);
}
}
for_it_end();
}
}
}