Added linkedlist_delete, funtions by index, one test was added and passed for checking when eliminate head, subsequent commits will add more tests for this function
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
static void linkedlist_test_append(void **state) {
|
||||
static void linkedlist_test_append_3_int(void **state) {
|
||||
(void) state;
|
||||
|
||||
LinkedList *ll;
|
||||
@@ -23,9 +23,30 @@ static void linkedlist_test_append(void **state) {
|
||||
linkedlist_destroy(ll);
|
||||
}
|
||||
|
||||
static void linkedlist_test_delete_head(void **state) {
|
||||
(void) state;
|
||||
|
||||
LinkedList *ll;
|
||||
linkedlist_create(&ll, sizeof(int));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
linkedlist_append(ll, &i);
|
||||
}
|
||||
linkedlist_delete(ll, 0);
|
||||
size_t len;
|
||||
linkedlist_len(ll,&len);
|
||||
assert_int_equal(len, 2);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
int n;
|
||||
linkedlist_get(ll, i, &n);
|
||||
assert_int_equal(n, i + 1);
|
||||
}
|
||||
linkedlist_destroy(ll);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(linkedlist_test_append),
|
||||
cmocka_unit_test(linkedlist_test_append_3_int),
|
||||
cmocka_unit_test(linkedlist_test_delete_head),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
Reference in New Issue
Block a user