diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-02-08 20:53:38 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-02-08 20:53:38 +0100 |
| commit | 98e809d42e23a2675c45754b9ca35d7e680252c8 (patch) | |
| tree | d2a832f8e4e988d6e04c34b9a3c134eb355639cc | |
| parent | 874ef49bff90ce144383efed0e69508586ff0d51 (diff) | |
| download | libasm_test-98e809d42e23a2675c45754b9ca35d7e680252c8.tar.gz libasm_test-98e809d42e23a2675c45754b9ca35d7e680252c8.tar.bz2 libasm_test-98e809d42e23a2675c45754b9ca35d7e680252c8.zip | |
School headers and ft_list_remove_if.s tests
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | functions_reference/ref_ft_atoi_base.c | 12 | ||||
| -rw-r--r-- | functions_reference/ref_ft_list_push_front.c | 12 | ||||
| -rw-r--r-- | functions_reference/ref_ft_list_remove_if.c | 16 | ||||
| -rw-r--r-- | functions_reference/ref_ft_list_size.c | 12 | ||||
| -rw-r--r-- | main.c | 4 | ||||
| -rw-r--r-- | test/ft_list_remove_if_test.c | 84 | ||||
| -rw-r--r-- | test/ft_list_sort_test.c | 9 |
8 files changed, 141 insertions, 14 deletions
@@ -6,7 +6,7 @@ # By: cacharle <marvin@42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/02/08 03:06:59 by cacharle #+# #+# # -# Updated: 2020/02/08 03:07:01 by cacharle ### ########.fr # +# Updated: 2020/02/08 20:42:54 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -39,10 +39,12 @@ SRC = main.c \ test/ft_list_size_test.c \ test/ft_list_push_front_test.c \ test/ft_list_sort_test.c \ + test/ft_list_remove_if_test.c \ functions_reference/ref_ft_atoi_base.c \ functions_reference/ref_ft_list_size.c \ functions_reference/ref_ft_list_push_front.c \ - functions_reference/ref_ft_list_sort.c + functions_reference/ref_ft_list_sort.c \ + functions_reference/ref_ft_list_remove_if.c OBJ = $(SRC:.c=.o) diff --git a/functions_reference/ref_ft_atoi_base.c b/functions_reference/ref_ft_atoi_base.c index d668254..6bd7052 100644 --- a/functions_reference/ref_ft_atoi_base.c +++ b/functions_reference/ref_ft_atoi_base.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ref_ft_atoi_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/08 03:20:16 by cacharle #+# #+# */ +/* Updated: 2020/02/08 03:20:18 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include <ctype.h> #include "libasm_test.h" diff --git a/functions_reference/ref_ft_list_push_front.c b/functions_reference/ref_ft_list_push_front.c index 22ca4a9..78b0877 100644 --- a/functions_reference/ref_ft_list_push_front.c +++ b/functions_reference/ref_ft_list_push_front.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ref_ft_list_push_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/08 03:20:23 by cacharle #+# #+# */ +/* Updated: 2020/02/08 03:20:24 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libasm_test.h" void diff --git a/functions_reference/ref_ft_list_remove_if.c b/functions_reference/ref_ft_list_remove_if.c index 8b55da1..c99cbea 100644 --- a/functions_reference/ref_ft_list_remove_if.c +++ b/functions_reference/ref_ft_list_remove_if.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ref_ft_list_remove_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/08 03:20:03 by cacharle #+# #+# */ +/* Updated: 2020/02/08 20:02:25 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libasm_test.h" void @@ -8,13 +20,13 @@ ref_ft_list_remove_if(t_list **begin_list, void *data_ref, if (begin_list == NULL || *begin_list == NULL) return ; - if (cmp(&(*begin_list)->val, data_ref) != 0) + if (cmp((*begin_list)->data, data_ref) != 0) { ref_ft_list_remove_if(&(*begin_list)->next, data_ref, cmp, free_fct); return ; } saved_next = (*begin_list)->next; - free_fct((*begin_list)->val); + free_fct((*begin_list)->data); free(*begin_list); *begin_list = saved_next; ref_ft_list_remove_if(begin_list, data_ref, cmp, free_fct); diff --git a/functions_reference/ref_ft_list_size.c b/functions_reference/ref_ft_list_size.c index d3e7583..c6348ba 100644 --- a/functions_reference/ref_ft_list_size.c +++ b/functions_reference/ref_ft_list_size.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ref_ft_list_size.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/08 03:20:11 by cacharle #+# #+# */ +/* Updated: 2020/02/08 03:20:12 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libasm_test.h" int @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:06:45 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:06:47 by cacharle ### ########.fr */ +/* Updated: 2020/02/08 20:43:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,6 @@ main(void) ft_list_push_front_test(); ft_list_size_test(); ft_list_sort_test(); - /* ft_list_remove_if_test(); */ + ft_list_remove_if_test(); return 0; } diff --git a/test/ft_list_remove_if_test.c b/test/ft_list_remove_if_test.c index d17b1e5..fb762eb 100644 --- a/test/ft_list_remove_if_test.c +++ b/test/ft_list_remove_if_test.c @@ -6,24 +6,100 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:08:42 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:08:42 by cacharle ### ########.fr */ +/* Updated: 2020/02/08 20:52:06 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" +static int +compar(void *a, void *ref) +{ + return *(int*)a - *(int*)ref; +} + static void -ft_list_remove_if_segfault(void) +free_fct(void *data) { + free(data); +} + +static int i0 = 0; +static int i1 = 1; +static int i2 = 2; +static int i3 = 3; +static t_list *tmp; +static t_list *expected; +static t_list *actual; + +#define FT_LIST_REMOVE_IF_EXPECT(fmt, ref) do { \ + expected = list_from_format(fmt); \ + actual = list_from_format(fmt); \ + ref_ft_list_remove_if(&expected, ref, compar, free_fct); \ + ft_list_remove_if(&actual, ref, compar, free_fct); \ + if (list_cmp(expected, actual) != 0) { \ + printf("KO: [COMPARE]: %s: expected: ", test_name); \ + list_print(expected); \ + printf(" got: "); \ + list_print(actual); \ + putchar('\n'); \ + } else \ + print_ok(); \ + list_destroy(expected); \ + list_destroy(actual); \ +} while (0); +static void +ft_list_remove_if_segfault(void) +{ + TEST_ASM_FUNCTION(tmp = list_from_format(""); + ft_list_remove_if(&tmp, &i0, compar, free_fct); + list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2"); + ft_list_remove_if(&tmp, &i3, compar, free_fct); + list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3"); + ft_list_remove_if(&tmp, &i3, compar, free_fct); + list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3"); + ft_list_remove_if(&tmp, &i1, compar, free_fct); + list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3"); + ft_list_remove_if(&tmp, &i2, compar, free_fct); + list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("987 3 9812 3 12 312 3 12491234989 3 908 3"); + ft_list_remove_if(&tmp, &i3, compar, free_fct); + list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 1 1 1 1 1 1 1"); + ft_list_remove_if(&tmp, &i1, compar, free_fct); + list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2 1 2 1 2 1 2"); + ft_list_remove_if(&tmp, &i1, compar, free_fct); + list_destroy(tmp)); + TEST_ASM_FUNCTION(tmp = list_from_format("1 2 1 2 1 2 1 2"); + ft_list_remove_if(&tmp, &i2, compar, free_fct); + list_destroy(tmp)); } + static void ft_list_remove_if_compare(void) { - + FT_LIST_REMOVE_IF_EXPECT("", &i0); + FT_LIST_REMOVE_IF_EXPECT("1 2", &i3); + FT_LIST_REMOVE_IF_EXPECT("1 2 3", &i3); + FT_LIST_REMOVE_IF_EXPECT("1 2 3", &i1); + FT_LIST_REMOVE_IF_EXPECT("1 2 3", &i2); + FT_LIST_REMOVE_IF_EXPECT("987 3 9812 3 12 312 3 12491234989 3 908 3", &i3); + FT_LIST_REMOVE_IF_EXPECT("1 1 1 1 1 1 1 1", &i1); + FT_LIST_REMOVE_IF_EXPECT("1 2 1 2 1 2 1 2", &i1); + FT_LIST_REMOVE_IF_EXPECT("1 2 1 2 1 2 1 2", &i2); } + void ft_list_remove_if_test(void) { - + test_name = "ft_list_remove_if.s"; + ft_list_remove_if_segfault(); + if (!signaled) + ft_list_remove_if_compare(); } diff --git a/test/ft_list_sort_test.c b/test/ft_list_sort_test.c index d50c1db..658abaf 100644 --- a/test/ft_list_sort_test.c +++ b/test/ft_list_sort_test.c @@ -6,13 +6,14 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/08 03:08:15 by cacharle #+# #+# */ -/* Updated: 2020/02/08 03:08:16 by cacharle ### ########.fr */ +/* Updated: 2020/02/08 20:39:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "libasm_test.h" -static int compar_int(void *a, void *b) +static int +compar_int(void *a, void *b) { return *(int*)a - *(int*)b; } @@ -38,8 +39,8 @@ static t_list *actual; list_destroy(actual); \ } while (0); -t_list* -st_merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)(void *, void*)); +/* t_list* */ +/* st_merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)(void *, void*)); */ static void ft_list_sort_segfault(void) |
