From 55dc897da6e81f2a26cfc7e66ac942824773498b Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 4 Jan 2022 11:51:58 +0800 Subject: temporary commit Now we can read grammars from a file. But we need to check if it works for reading strings still. --- src/test/check_list.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/test/check_list.c') diff --git a/src/test/check_list.c b/src/test/check_list.c index 8677cd3..fe23b2b 100644 --- a/src/test/check_list.c +++ b/src/test/check_list.c @@ -2,7 +2,7 @@ #include #include "../list.h" -void +static void print_int(void *p) { printf("%d\n", *((int *)p)); @@ -155,6 +155,8 @@ main(U_ATTR int argc, U_ATTR char **argv) exit(1); } + eprintf("Successfully created LS2!\n"); + for (NUM i = 0; i < 5; i++) { int *pointer = malloc(sizeof *pointer * 1); @@ -197,7 +199,7 @@ main(U_ATTR int argc, U_ATTR char **argv) } NUM arr[10]; - + for (NUM i = 0; i < 10; i++) { arr[i] = i*i-i+1; if (add_to_list(ls, arr+i)) { @@ -211,7 +213,28 @@ main(U_ATTR int argc, U_ATTR char **argv) destroy_list(ls, 0); + /* test array_to_list */ + int *arr3 = MYALLOC(int, 20); + + void **arr2 = NULL; + + for (NUM i = 0; i < 20; i++) { + *(arr3+i) = i*i+i+1; + } + + arr2 = MYALLOC(void *, 20); + + for (NUM i = 0; i < 20; i++) *(arr2+i) = arr3+i; + + ls = array_to_list(arr2, 20); + + printf("Printing a list from an array\n"); + + map_list(ls, print_int); + + destroy_list(ls, 2); + printf("Every test is successful!\n"); - + return 0; } -- cgit v1.2.3-18-g5258