aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--functions_reference/ref_ft_atoi_base.c12
-rw-r--r--functions_reference/ref_ft_list_push_front.c12
-rw-r--r--functions_reference/ref_ft_list_remove_if.c16
-rw-r--r--functions_reference/ref_ft_list_size.c12
-rw-r--r--main.c4
-rw-r--r--test/ft_list_remove_if_test.c84
-rw-r--r--test/ft_list_sort_test.c9
8 files changed, 141 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 89cb00a..7e5fc71 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/main.c b/main.c
index 5749ea7..fbd247b 100644
--- a/main.c
+++ b/main.c
@@ -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)