Update list tests
This commit is contained in:
parent
39c17f956a
commit
ab8aad910c
@ -11,7 +11,7 @@ int main(int argc, char** argv) {
|
||||
list_init(&x);
|
||||
|
||||
for (int i = 0, n = 12 + random_boolean(); i < n; ++i) {
|
||||
list_push_random(&x, 0);
|
||||
list_push_random(&x, random_boolean());
|
||||
}
|
||||
list_sort(&x);
|
||||
list_info(&x);
|
||||
|
@ -77,6 +77,6 @@ static void list_print(const vtype_list* x, const char* prefix) {
|
||||
}
|
||||
|
||||
static void list_info(const vtype_list* x) {
|
||||
printf("List has \e[m\e[32m%lu\e[m\e[36m elements\e[m\n", list_size(x));
|
||||
printf("\e[36mList has \e[m\e[32m%lu\e[m\e[36m elements\e[m\n", list_size(x));
|
||||
put_separator();
|
||||
}
|
||||
|
32
tests/src/list/remove.c
Normal file
32
tests/src/list/remove.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include "plug.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
test_init(argc, argv);
|
||||
|
||||
vtype_list x;
|
||||
|
||||
list_init(&x);
|
||||
|
||||
for (int i = 0, c = random_uint8()%16; i < 12; ++i) {
|
||||
if (i == c) {
|
||||
list_push_back(&x, 0);
|
||||
} else list_push_random(&x, random_boolean());
|
||||
}
|
||||
|
||||
list_info(&x);
|
||||
list_print(&x, 0);
|
||||
|
||||
for (int i = 0, n = list_countof(&x, 0); i < n; ++i) {
|
||||
int index = list_indexof(&x, 0);
|
||||
list_remove(&x, 0);
|
||||
|
||||
printf("\e[36mRemove element with index \e[m\e[32;1m%d\e[m\e[36m from list\e[m\n", index);
|
||||
}
|
||||
put_separator();
|
||||
list_print(&x, "cleaned");
|
||||
|
||||
list_free(&x);
|
||||
}
|
Loading…
Reference in New Issue
Block a user