aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile19
-rw-r--r--functions_reference/ref_ft_list_sort.c45
-rw-r--r--helper.c12
-rw-r--r--helper_list.c14
-rw-r--r--libasm_test.h12
-rw-r--r--main.c14
-rw-r--r--test/ft_atoi_base_test.c12
-rw-r--r--test/ft_list_push_front_test.c20
-rw-r--r--test/ft_list_remove_if_test.c12
-rw-r--r--test/ft_list_size_test.c12
-rw-r--r--test/ft_list_sort_test.c64
-rw-r--r--test/ft_read_test.c12
-rw-r--r--test/ft_strcmp_test.c12
-rw-r--r--test/ft_strcpy_test.c12
-rw-r--r--test/ft_strdup_test.c12
-rw-r--r--test/ft_strlen_test.c12
-rw-r--r--test/ft_write_test.c12
17 files changed, 281 insertions, 27 deletions
diff --git a/Makefile b/Makefile
index 626d633..89cb00a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,15 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# Makefile :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/02/08 03:06:59 by cacharle #+# #+# #
+# Updated: 2020/02/08 03:07:01 by cacharle ### ########.fr #
+# #
+# **************************************************************************** #
+
RM = rm -f
UNAME = $(shell uname)
@@ -10,7 +22,7 @@ endif
LIBASM_PATH = ../libasm
CC = gcc
-CCFLAGS = -I. -Wall -Wextra
+CCFLAGS = -I. -Wall -Wextra -g
LDFLAGS = -L$(LIBASM_PATH) -lasm
NAME = runtest
@@ -26,10 +38,11 @@ SRC = main.c \
test/ft_atoi_base_test.c \
test/ft_list_size_test.c \
test/ft_list_push_front_test.c \
+ test/ft_list_sort_test.c \
functions_reference/ref_ft_atoi_base.c \
functions_reference/ref_ft_list_size.c \
- functions_reference/ref_ft_list_push_front.c
- # ft_list_sort_test.c ft_list_remove_if_test.c \
+ functions_reference/ref_ft_list_push_front.c \
+ functions_reference/ref_ft_list_sort.c
OBJ = $(SRC:.c=.o)
diff --git a/functions_reference/ref_ft_list_sort.c b/functions_reference/ref_ft_list_sort.c
index b03c84b..e770fa0 100644
--- a/functions_reference/ref_ft_list_sort.c
+++ b/functions_reference/ref_ft_list_sort.c
@@ -1,45 +1,60 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ref_ft_list_sort.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 02:49:28 by cacharle #+# #+# */
+/* Updated: 2020/02/08 02:49:29 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
static t_list*
-merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)())
+merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)(void *, void*))
{
- t_list *merged = NULL;
+ t_list *merged = 0x0;
- if (l1 == NULL && l2 == NULL)
- return NULL;
- if (l1 == NULL)
+ if (l1 == 0x0)
return l2;
- if (l2 == NULL)
+ if (l2 == 0x0)
return l1;
- merged = cmp(l1->data, l2->data) < 0 ? l1 : l2;
if (cmp(l1->data, l2->data) < 0)
+ {
+ merged = l1;
merged->next = merge_sorted_list(l1->next, l2, cmp);
+ }
else
+ {
+ merged = l2;
merged->next = merge_sorted_list(l1, l2->next, cmp);
+ }
return merged;
}
void
-ref_ft_list_sort(t_list **begin_list, int (*cmp)())
+ref_ft_list_sort(t_list **begin_list, int (*cmp)(void *, void*))
{
- if (begin_list == NULL || *begin_list == NULL
- || (*begin_list)->next == NULL)
+ if (begin_list == 0x0 || *begin_list == 0x0
+ || (*begin_list)->next == 0x0)
return ;
t_list *fast = (*begin_list)->next;
t_list *slow = *begin_list;
- while (fast != NULL)
+ while (fast != 0x0)
{
fast = fast->next;
- if (fast != NULL)
+ if (fast != 0x0)
{
fast = fast->next;
slow = slow->next;
}
}
t_list *middle = slow->next;
- slow->next = NULL;
+ slow->next = 0x0;
- sortList(begin_list, cmp);
- sortList(&middle, cmp);
+ ref_ft_list_sort(begin_list, cmp);
+ ref_ft_list_sort(&middle, cmp);
*begin_list = merge_sorted_list(*begin_list, middle, cmp);
}
diff --git a/helper.c b/helper.c
index ebfa232..c831090 100644
--- a/helper.c
+++ b/helper.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* helper.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:07:07 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:07:08 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
diff --git a/helper_list.c b/helper_list.c
index 5ab94be..cfeb9f3 100644
--- a/helper_list.c
+++ b/helper_list.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* helper_list.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:07:14 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:07:15 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
int*
@@ -92,7 +104,7 @@ list_print(t_list *list)
{
while (list != NULL)
{
- printf("[%p] -> ", (int*)list->data);
+ printf("[%d] -> ", *(int*)list->data);
list = list->next;
}
printf("(null)");
diff --git a/libasm_test.h b/libasm_test.h
index 28f516e..b3805e4 100644
--- a/libasm_test.h
+++ b/libasm_test.h
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libasm_test.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:07:19 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:07:20 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#ifndef LIBASM_TEST_H
# define LIBASM_TEST_H
diff --git a/main.c b/main.c
index 8a170ff..5749ea7 100644
--- a/main.c
+++ b/main.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:06:45 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:06:47 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
int
@@ -15,7 +27,7 @@ main(void)
ft_atoi_base_test();
ft_list_push_front_test();
ft_list_size_test();
- /* ft_list_sort_test(); */
+ ft_list_sort_test();
/* ft_list_remove_if_test(); */
return 0;
}
diff --git a/test/ft_atoi_base_test.c b/test/ft_atoi_base_test.c
index 8801565..974fa0c 100644
--- a/test/ft_atoi_base_test.c
+++ b/test/ft_atoi_base_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_atoi_base_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:07:27 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:07:38 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
static int expected_ret;
diff --git a/test/ft_list_push_front_test.c b/test/ft_list_push_front_test.c
index 2f9cf59..00b8c13 100644
--- a/test/ft_list_push_front_test.c
+++ b/test/ft_list_push_front_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_push_front_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:08:24 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:08:25 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
static t_list *tmp;
@@ -31,10 +43,10 @@ ft_list_push_front_segfault(void)
TEST_ASM_FUNCTION(tmp = list_from_format("1 2"); ft_list_push_front(&tmp, create_data_elem(0)); list_destroy(tmp));
TEST_ASM_FUNCTION(
tmp = list_from_format("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20");
- ft_list_push_front(tmp, create_data_elem(4));
- ft_list_push_front(tmp, create_data_elem(4));
- ft_list_push_front(tmp, create_data_elem(4));
- ft_list_push_front(tmp, create_data_elem(4));
+ ft_list_push_front(&tmp, create_data_elem(4));
+ ft_list_push_front(&tmp, create_data_elem(4));
+ ft_list_push_front(&tmp, create_data_elem(4));
+ ft_list_push_front(&tmp, create_data_elem(4));
list_destroy(tmp);
);
}
diff --git a/test/ft_list_remove_if_test.c b/test/ft_list_remove_if_test.c
index e574949..d17b1e5 100644
--- a/test/ft_list_remove_if_test.c
+++ b/test/ft_list_remove_if_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_remove_if_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:08:42 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:08:42 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
static void
diff --git a/test/ft_list_size_test.c b/test/ft_list_size_test.c
index 5c36095..a6cf23a 100644
--- a/test/ft_list_size_test.c
+++ b/test/ft_list_size_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_size_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:08:20 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:08:21 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
static t_list *tmp;
diff --git a/test/ft_list_sort_test.c b/test/ft_list_sort_test.c
index e9fe2da..d50c1db 100644
--- a/test/ft_list_sort_test.c
+++ b/test/ft_list_sort_test.c
@@ -1,17 +1,75 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_sort_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:08:15 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:08:16 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
+static int compar_int(void *a, void *b)
+{
+ return *(int*)a - *(int*)b;
+}
+
+static t_list *tmp;
+static t_list *expected;
+static t_list *actual;
+
+#define FT_LIST_SORT_EXPECT(fmt) do { \
+ expected = list_from_format(fmt); \
+ actual = list_from_format(fmt); \
+ ref_ft_list_sort(&expected, compar_int); \
+ ft_list_sort(&actual, compar_int); \
+ 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);
+
+t_list*
+st_merge_sorted_list(t_list* l1, t_list* l2, int (*cmp)(void *, void*));
+
static void
ft_list_sort_segfault(void)
{
-
+ TEST_ASM_FUNCTION(tmp = list_from_format(""); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
+ TEST_ASM_FUNCTION(tmp = list_from_format("1"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
+ TEST_ASM_FUNCTION(tmp = list_from_format("1 2"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
+ TEST_ASM_FUNCTION(tmp = list_from_format("1 2 3"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
+ TEST_ASM_FUNCTION(tmp = list_from_format("-1 0 1 2 3 4 5 6"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
+ TEST_ASM_FUNCTION(tmp = list_from_format("98 12 12 45 1 -1 232 34 23"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
+ TEST_ASM_FUNCTION(tmp = list_from_format("12 45 1 -1 232 34 23 87879"); ft_list_sort(&tmp, compar_int); list_destroy(tmp));
}
+
static void
ft_list_sort_compare(void)
{
-
+ FT_LIST_SORT_EXPECT("");
+ FT_LIST_SORT_EXPECT("1");
+ FT_LIST_SORT_EXPECT("1 2");
+ FT_LIST_SORT_EXPECT("1 2 3");
+ FT_LIST_SORT_EXPECT("-1 0 1 2 3 4 5 6");
+ FT_LIST_SORT_EXPECT("98 12 12 45 1 -1 232 34 23");
+ FT_LIST_SORT_EXPECT("12 45 1 -1 232 34 23 87879");
}
+
void
ft_list_sort_test(void)
{
-
+ test_name = "ft_list_sort.s";
+ ft_list_sort_segfault();
+ if (!signaled)
+ ft_list_sort_compare();
}
diff --git a/test/ft_read_test.c b/test/ft_read_test.c
index 5b29803..0b4e5aa 100644
--- a/test/ft_read_test.c
+++ b/test/ft_read_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_read_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:07:44 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:07:45 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
#define FT_READ_BUF_SIZE (1 << 12)
diff --git a/test/ft_strcmp_test.c b/test/ft_strcmp_test.c
index fa62157..5f13ce7 100644
--- a/test/ft_strcmp_test.c
+++ b/test/ft_strcmp_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcmp_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:08:03 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:08:03 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
static void
diff --git a/test/ft_strcpy_test.c b/test/ft_strcpy_test.c
index c8ec474..7929b2f 100644
--- a/test/ft_strcpy_test.c
+++ b/test/ft_strcpy_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strcpy_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:07:58 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:07:59 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
#define FT_STRCPY_BUF_SIZE (1 << 12)
diff --git a/test/ft_strdup_test.c b/test/ft_strdup_test.c
index 5ca7850..f15dedd 100644
--- a/test/ft_strdup_test.c
+++ b/test/ft_strdup_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strdup_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:08:06 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:08:07 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
static char *tmp;
diff --git a/test/ft_strlen_test.c b/test/ft_strlen_test.c
index 7229316..1c500ae 100644
--- a/test/ft_strlen_test.c
+++ b/test/ft_strlen_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strlen_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:07:53 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:07:53 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
static void
diff --git a/test/ft_write_test.c b/test/ft_write_test.c
index c44625e..a579916 100644
--- a/test/ft_write_test.c
+++ b/test/ft_write_test.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_write_test.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/08 03:07:48 by cacharle #+# #+# */
+/* Updated: 2020/02/08 03:07:49 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libasm_test.h"
#define FT_WRITE_BUF_SIZE (1 << 12)