removing the libft of rparodi
This commit is contained in:
parent
0391323626
commit
be6038dcc8
523 changed files with 724 additions and 3336 deletions
33
libft/tests/ft_args/args_tests.c
Normal file
33
libft/tests/ft_args/args_tests.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* args_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/18 17:02:31 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 18:33:18 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/tests.h"
|
||||
#include "tests/args_tests.h"
|
||||
|
||||
int parse_args_test(void)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
int tests_args(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test test[] = {
|
||||
{"getset_version", getset_version_test}, {"getset_progname", \
|
||||
getset_program_name_test}, {"getset_opt_list", getset_opt_list_test},
|
||||
{"parse_args", parse_args_test}, {"setup_prog", tests_setup_prog},
|
||||
{"getset_custom_parser", getset_custom_checker_test}, {NULL, NULL}};
|
||||
|
||||
collect = 0;
|
||||
run_test(test, &collect);
|
||||
return (collect);
|
||||
}
|
||||
30
libft/tests/ft_args/tests_custom_checker.c
Normal file
30
libft/tests/ft_args/tests_custom_checker.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_custom_checker.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/31 18:15:10 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/01 14:28:04 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_args.h"
|
||||
|
||||
static bool loc_checker(const void *arg)
|
||||
{
|
||||
const char *str = (const char *)arg;
|
||||
|
||||
if (str[0] == 'a')
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
int getset_custom_checker_test(void)
|
||||
{
|
||||
ft_arg_set_custom_checker(loc_checker);
|
||||
if (ft_arg_get_custom_checker() != loc_checker)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
37
libft/tests/ft_args/tests_optlist.c
Normal file
37
libft/tests/ft_args/tests_optlist.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optlist.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 15:52:31 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/28 15:52:33 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_args.h"
|
||||
#include "ft_args_types.h"
|
||||
#include <stddef.h>
|
||||
|
||||
static void empty(void *ar, char *arg)
|
||||
{
|
||||
(void)ar;
|
||||
(void)arg;
|
||||
}
|
||||
|
||||
int getset_opt_list_test(void)
|
||||
{
|
||||
const t_opt *op2 = NULL;
|
||||
const t_opt op1[] = {
|
||||
{"--test", 't', &empty, 0},
|
||||
};
|
||||
|
||||
ft_set_opt_list(op1);
|
||||
if (ft_get_opt_list() != op1)
|
||||
return (1);
|
||||
ft_set_opt_list(op2);
|
||||
if (ft_get_opt_list() != op1)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
30
libft/tests/ft_args/tests_progname.c
Normal file
30
libft/tests/ft_args/tests_progname.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_progname.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:37:47 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 22:38:23 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_args.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
int getset_program_name_test(void)
|
||||
{
|
||||
char *s1;
|
||||
char *s2;
|
||||
|
||||
s1 = "toto";
|
||||
s2 = 0;
|
||||
ft_set_progname(s1);
|
||||
if (ft_progname() != s1)
|
||||
return (ft_putstr_fd(ft_progname(), 2), 1);
|
||||
ft_set_progname(s2);
|
||||
if (ft_progname() == s2)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
26
libft/tests/ft_args/tests_setup_prog.c
Normal file
26
libft/tests/ft_args/tests_setup_prog.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_setup_prog.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 15:55:09 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/28 16:04:22 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_args.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
int tests_setup_prog(void)
|
||||
{
|
||||
const char *argv[] = {"dummy_prog", "--test", NULL};
|
||||
|
||||
ft_setup_prog(argv);
|
||||
if (ft_progname() != argv[0])
|
||||
return (1);
|
||||
if (ft_strcmp(ft_progversion(), VERSION) != 0)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
31
libft/tests/ft_args/tests_version.c
Normal file
31
libft/tests/ft_args/tests_version.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_version.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:37:13 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 22:38:27 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_args.h"
|
||||
#include "ft_string.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int getset_version_test(void)
|
||||
{
|
||||
char *s1;
|
||||
char *s2;
|
||||
|
||||
s1 = "toto";
|
||||
s2 = 0;
|
||||
ft_set_version(s1);
|
||||
if (ft_progversion() != s1)
|
||||
return (ft_putstr_fd(ft_progversion(), STDERR_FILENO), 1);
|
||||
ft_set_version(s2);
|
||||
if (ft_progversion() == s2)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
52
libft/tests/ft_list/dl_tests/dl_list_tests.c
Normal file
52
libft/tests/ft_list/dl_tests/dl_list_tests.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dl_list_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/12 20:37:03 by iron #+# #+# */
|
||||
/* Updated: 2024/05/30 12:10:48 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/tests.h"
|
||||
#include "tests/dl_tests.h"
|
||||
|
||||
static const t_test *init_tests(void)
|
||||
{
|
||||
static const t_test var[] = {
|
||||
{"add_front", t_dl_add_front}, {"add_back", \
|
||||
t_dl_add_back}, {"apply", t_dl_apply}, {\
|
||||
"apply_range", t_dl_apply_range}, {\
|
||||
"apply_range_node", t_dl_apply_range_node}, {\
|
||||
"clear", t_dl_clear}, {"clear_range", \
|
||||
t_dl_clear_range}, {"create", t_dl_create}, {\
|
||||
"copy_node", t_dl_copy_node}, {"copy_list", \
|
||||
t_dl_copy_list}, {"delete_self", \
|
||||
t_dl_delete_self}, {"delete_range", \
|
||||
t_dl_delete_range}, {"delete", t_dl_delete}, \
|
||||
{"find", t_dl_find}, {"get_datas", \
|
||||
t_dl_get_datas}, {"get_nodes", t_dl_get_nodes}, \
|
||||
{"at", t_dl_at}, {"begin", \
|
||||
t_dl_begin}, {"end", t_dl_end}, {\
|
||||
"map", t_dl_map}, {"new", t_dl_new}, \
|
||||
{"pop", t_dl_pop}, {"pop_back", \
|
||||
t_dl_pop_back}, {"push", t_dl_push}, \
|
||||
{"push_back", t_dl_push_back}, {"rev", \
|
||||
t_dl_rev}, {"size", t_dl_size}, {\
|
||||
"size_of_data", t_dl_size_of_data}, {\
|
||||
"subrange", t_dl_subrange}, {NULL, NULL}};
|
||||
|
||||
return (var);
|
||||
}
|
||||
|
||||
int tests_doubly_linked_list_all(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test *test = init_tests();
|
||||
|
||||
collect = 0;
|
||||
run_test(test, &collect);
|
||||
return (collect);
|
||||
}
|
||||
26
libft/tests/ft_list/dl_tests/dl_tests_utils.c
Normal file
26
libft/tests/ft_list/dl_tests/dl_tests_utils.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dl_test_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 11:08:48 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 14:27:24 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void create_2elem_dlist(t_dlist **list, void **data1, void **data2)
|
||||
{
|
||||
*data1 = malloc(sizeof(int));
|
||||
*data2 = malloc(sizeof(int));
|
||||
*(int *)*data1 = 42;
|
||||
*(int *)*data2 = 21;
|
||||
*list = NULL;
|
||||
ft_dl_push(list, *data1);
|
||||
ft_dl_push_back(list, *data2);
|
||||
}
|
||||
73
libft/tests/ft_list/dl_tests/tests_dlist_add.c
Normal file
73
libft/tests/ft_list/dl_tests/tests_dlist_add.c
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_add.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:48:41 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:54:39 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_add_front(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
data2 = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
*data2 = 21;
|
||||
list = ft_dl_create(data2);
|
||||
ft_dl_add_front(&list, NULL);
|
||||
if (!list || list->next)
|
||||
return (1);
|
||||
else
|
||||
{
|
||||
ft_dl_add_front(&list, ft_dl_create(data));
|
||||
if (!list || list->data != data || !list->next)
|
||||
return (1);
|
||||
else if (list->next->data != data2 || list->next->next)
|
||||
return (1);
|
||||
else if (list->next->prev != list)
|
||||
return (1);
|
||||
}
|
||||
ft_dl_clear(&list, free);
|
||||
ft_dl_add_front(NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_add_back(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
list = NULL;
|
||||
data = malloc(sizeof(int));
|
||||
data2 = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
*data2 = 21;
|
||||
ft_dl_add_back(&list, ft_dl_create(data));
|
||||
ft_dl_add_back(&list, NULL);
|
||||
if (!list || list->next)
|
||||
return (1);
|
||||
else
|
||||
{
|
||||
ft_dl_add_back(&list, ft_dl_create(data2));
|
||||
if (!list || list->data != data || !list->next || \
|
||||
list->next->data != data2)
|
||||
return (1);
|
||||
else if (list->next->next || list->next->prev != list)
|
||||
return (1);
|
||||
}
|
||||
ft_dl_clear(&list, free);
|
||||
ft_dl_add_front(NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
72
libft/tests/ft_list/dl_tests/tests_dlist_apply.c
Normal file
72
libft/tests/ft_list/dl_tests/tests_dlist_apply.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_apply.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:55:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 11:48:52 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void dnode_add42(t_dlist *node)
|
||||
{
|
||||
*(int *)node->data += 42;
|
||||
}
|
||||
|
||||
int t_dl_apply(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
ft_dl_apply(list, add42);
|
||||
if (ft_dl_size(list) != 2)
|
||||
return (1);
|
||||
else if (*(int *)list->data != 84)
|
||||
return (2);
|
||||
else if (*(int *)list->next->data != 63)
|
||||
return (3);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_apply_range(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
ft_dl_apply_range(list, list->next, add42);
|
||||
if (ft_dl_size(list) != 2)
|
||||
return (1);
|
||||
else if (*(int *)list->data != 84 || \
|
||||
*(int *)list->next->data != 21)
|
||||
return (1);
|
||||
return (ft_dl_clear(&list, free), 0);
|
||||
}
|
||||
|
||||
int t_dl_apply_range_node(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
ft_dl_apply_range_node(list, list->next, dnode_add42);
|
||||
if (ft_dl_size(list) != 2)
|
||||
return (1);
|
||||
else if (*(int *)list->data != 84 || \
|
||||
*(int *)list->next->data != 21)
|
||||
return (1);
|
||||
return (ft_dl_clear(&list, free), 0);
|
||||
}
|
||||
68
libft/tests/ft_list/dl_tests/tests_dlist_clear.c
Normal file
68
libft/tests/ft_list/dl_tests/tests_dlist_clear.c
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_clear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:56:57 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:57:45 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_clear(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
list = ft_dl_create(data);
|
||||
ft_dl_clear(&list, NULL);
|
||||
list = ft_dl_create(data);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
//
|
||||
//ft_dl_add_back(&list, ft_dl_create(data3))
|
||||
// data -> data2 -> data3
|
||||
//ft_dl_clear_range(list->next, list->next->next, NULL)
|
||||
// data -> NULL -> data3
|
||||
//ft_dl_add_back(&list, ft_dl_create(data2))
|
||||
// data -> NULL -> data3 -> data2
|
||||
//ft_dl_clear_range(list->next->next, NULL, free)
|
||||
// data -> NULL -> NULL -> NULL
|
||||
//ft_dl_delete_range(list, NULL, NULL)
|
||||
// delete nodes
|
||||
//
|
||||
|
||||
int t_dl_clear_range(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
int *data3;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 63;
|
||||
ft_dl_add_back(&list, ft_dl_create(data3));
|
||||
ft_dl_clear_range(list->next, list->next->next, NULL);
|
||||
if ((ft_dl_size(list) != 3) || (list->data != data || \
|
||||
list->next->data || list->next->next->data != data3))
|
||||
return (1);
|
||||
ft_dl_add_back(&list, ft_dl_create(data2));
|
||||
ft_dl_clear_range(list->next->next, NULL, free);
|
||||
if (ft_dl_size(list) != 4 || list->data != data \
|
||||
|| list->next->data || list->next->next->data)
|
||||
return (2);
|
||||
ft_dl_clear_range(list, NULL, free);
|
||||
ft_dl_clear_range(NULL, NULL, free);
|
||||
ft_dl_delete_range(list, NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
65
libft/tests/ft_list/dl_tests/tests_dlist_copy.c
Normal file
65
libft/tests/ft_list/dl_tests/tests_dlist_copy.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_copy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:58:55 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:59:26 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_copy_node(void)
|
||||
{
|
||||
int *data;
|
||||
t_dlist *list;
|
||||
t_dlist *copy;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
list = ft_dl_create(data);
|
||||
copy = ft_dl_copy_node(list);
|
||||
if (!copy)
|
||||
return (1);
|
||||
else if (copy->data != list->data)
|
||||
return (1);
|
||||
else if (copy->next != list->next)
|
||||
return (1);
|
||||
else if (copy->prev != list->prev)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
ft_dl_clear(©, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_copy_list(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
t_dlist *copy;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
copy = ft_dl_copy_list(list);
|
||||
if (!copy)
|
||||
return (1);
|
||||
else if (copy->data != list->data)
|
||||
return (1);
|
||||
else if (!copy->next)
|
||||
return (1);
|
||||
else if (copy->next->data != list->next->data)
|
||||
return (1);
|
||||
else if (copy->next->next)
|
||||
return (1);
|
||||
else if (copy->next->prev != copy)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
ft_dl_clear(©, NULL);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_list/dl_tests/tests_dlist_create.c
Normal file
34
libft/tests/ft_list/dl_tests/tests_dlist_create.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_create.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:58:15 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 17:00:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_create(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
list = ft_dl_create(data);
|
||||
if (!list)
|
||||
return (1);
|
||||
else if (list->data != data)
|
||||
return (1);
|
||||
else if (list->next)
|
||||
return (1);
|
||||
else if (list->prev)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
110
libft/tests/ft_list/dl_tests/tests_dlist_delete.c
Normal file
110
libft/tests/ft_list/dl_tests/tests_dlist_delete.c
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_delete.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:01:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 17:20:30 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_delete_self(void)
|
||||
{
|
||||
int *data;
|
||||
int *data2;
|
||||
int *data3;
|
||||
t_dlist *list;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 63;
|
||||
ft_dl_add_back(&list, ft_dl_create(data3));
|
||||
ft_dl_delete_self(list->next, NULL);
|
||||
if (!list || list->data != data || !list->next || \
|
||||
list->next->data != data3 || list->next->next)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 63;
|
||||
*data2 = 21;
|
||||
list = ft_dl_create(data3);
|
||||
ft_dl_add_back(&list, ft_dl_create(data2));
|
||||
ft_dl_delete_self(list->next, free);
|
||||
if (list->next || list->data != data3)
|
||||
return (1);
|
||||
return (ft_dl_clear(&list, free), \
|
||||
ft_dl_delete_self(NULL, NULL), 0);
|
||||
}
|
||||
/*
|
||||
ft_dl_add_back(&list, ft_dl_create(data3));
|
||||
// NULL <-(42)<=>(21)<=>(63)-> NULL
|
||||
list2 = list->next;
|
||||
// 42 <-(21)<=>(63)-> NULL
|
||||
nb_deleted = ft_dl_delete_range(list, list->next, NULL);
|
||||
// NULL <-(21)<=>(63)-> NULL
|
||||
ft_dl_add_front(&list2, ft_dl_create(data));
|
||||
// NULL <-(42)<=>(21)<=>(63)-> NULL
|
||||
list = list2;
|
||||
nb_deleted = ft_dl_delete_range(list->next, list->next->next, free);
|
||||
// NULL <-(42)<=>(63)-> NULL
|
||||
*/
|
||||
|
||||
int t_dl_delete_range(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
t_dlist *list2;
|
||||
int *data_array[3];
|
||||
int nb_deleted;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data_array[0], (void **)&data_array[1]);
|
||||
data_array[2] = malloc(sizeof(int));
|
||||
*data_array[2] = 63;
|
||||
ft_dl_add_back(&list, ft_dl_create(data_array[2]));
|
||||
list2 = list->next;
|
||||
nb_deleted = ft_dl_delete_range(list, list->next, NULL);
|
||||
if (nb_deleted != 1 || ft_dl_size(list2) != 2 || *(int *)list2->data \
|
||||
!= *data_array[1] || *(int *)list2->next->data != *data_array[2])
|
||||
return (1);
|
||||
ft_dl_add_front(&list2, ft_dl_create(data_array[0]));
|
||||
list = list2;
|
||||
nb_deleted = ft_dl_delete_range(list->next, list->next->next, free);
|
||||
if (nb_deleted != 1 || ft_dl_size(list) != 2 || *(int *)list2->data \
|
||||
!= *data_array[0] || *(int *)list2->next->data != *data_array[2])
|
||||
return (1);
|
||||
return (ft_dl_clear(&list2, free), 0);
|
||||
}
|
||||
|
||||
int t_dl_delete(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
int *data3;
|
||||
int nb_deleted;
|
||||
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 63;
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
ft_dl_add_back(&list, ft_dl_create(data3));
|
||||
nb_deleted = ft_dl_delete(&list, NULL);
|
||||
if (nb_deleted != 3)
|
||||
return (1);
|
||||
else if (list)
|
||||
return (1);
|
||||
ft_dl_add_front(&list, ft_dl_create(data));
|
||||
ft_dl_add_back(&list, ft_dl_create(data2));
|
||||
ft_dl_add_back(&list, ft_dl_create(data3));
|
||||
nb_deleted = ft_dl_delete(&list, free);
|
||||
if (nb_deleted != 3)
|
||||
return (1);
|
||||
else if (list)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
45
libft/tests/ft_list/dl_tests/tests_dlist_find.c
Normal file
45
libft/tests/ft_list/dl_tests/tests_dlist_find.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_find.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:01:51 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 11:49:02 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
ft_dl_add_back(&list, ft_dl_create(data2));
|
||||
// data-> data2
|
||||
*/
|
||||
|
||||
int t_dl_find(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
t_dlist *found_ret[3];
|
||||
int *data;
|
||||
int *data2;
|
||||
int *data3;
|
||||
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 21;
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
found_ret[0] = ft_dl_find(list, data2, NULL);
|
||||
found_ret[1] = ft_dl_find(list, data3, NULL);
|
||||
found_ret[2] = ft_dl_find(list, data3, cmp_int);
|
||||
if (ft_dl_size(found_ret[0]) != 1 || found_ret[0]->data != data2)
|
||||
return (1);
|
||||
else if (found_ret[1])
|
||||
return (1);
|
||||
else if (ft_dl_size(found_ret[2]) != 1 || found_ret[2]->data != data2)
|
||||
return (1);
|
||||
return (ft_dl_clear(&list, free), free(data3), 0);
|
||||
}
|
||||
60
libft/tests/ft_list/dl_tests/tests_dlist_get.c
Normal file
60
libft/tests/ft_list/dl_tests/tests_dlist_get.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_get.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:04:21 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 17:04:43 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_get_datas(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
void **datas;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
datas = ft_dl_get_datas(list);
|
||||
if (!datas)
|
||||
return (1);
|
||||
else if (datas[0] != data)
|
||||
return (1);
|
||||
else if (datas[1] != data2)
|
||||
return (1);
|
||||
if (ft_dl_get_datas(NULL))
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
free(datas);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_get_nodes(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
t_dlist **nodes;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
nodes = ft_dl_get_nodes(list);
|
||||
if (!nodes)
|
||||
return (1);
|
||||
else if (nodes[0] != list)
|
||||
return (1);
|
||||
else if (nodes[1] != list->next)
|
||||
return (1);
|
||||
if (ft_dl_get_nodes(NULL))
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
free(nodes);
|
||||
return (0);
|
||||
}
|
||||
81
libft/tests/ft_list/dl_tests/tests_dlist_iterators.c
Normal file
81
libft/tests/ft_list/dl_tests/tests_dlist_iterators.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_iterators.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:04:13 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 17:04:17 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_at(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
t_dlist *at;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
at = ft_dl_at(list, 1);
|
||||
if (!at)
|
||||
return (1);
|
||||
else if (at->data != data2)
|
||||
return (1);
|
||||
else if (at->next)
|
||||
return (1);
|
||||
else if (at->prev != list)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_begin(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
t_dlist *begin;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
begin = ft_dl_begin(list->next);
|
||||
if (!begin)
|
||||
return (1);
|
||||
else if (begin != list)
|
||||
return (1);
|
||||
else if (begin->data != data)
|
||||
return (1);
|
||||
else if (begin->next != list->next)
|
||||
return (1);
|
||||
else if (begin->prev)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_end(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
t_dlist *end;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data, (void **)&data2);
|
||||
end = ft_dl_end(list);
|
||||
if (!end)
|
||||
return (1);
|
||||
else if (end->data != data2)
|
||||
return (1);
|
||||
else if (end->next)
|
||||
return (1);
|
||||
else if (end->prev != list)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
46
libft/tests/ft_list/dl_tests/tests_dlist_map.c
Normal file
46
libft/tests/ft_list/dl_tests/tests_dlist_map.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:06:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/19 18:24:00 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_map(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
t_dlist *map;
|
||||
t_dlist *map2;
|
||||
int *data1;
|
||||
int *data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data1, (void **)&data2);
|
||||
map2 = ft_dl_map(list, NULL, free);
|
||||
map = ft_dl_map(list, add42_ret, free);
|
||||
if (!map)
|
||||
return (1);
|
||||
else if (*(int *)map->data != 84)
|
||||
return (1);
|
||||
else if (!map->next)
|
||||
return (1);
|
||||
else if (*(int *)map->next->data != 63)
|
||||
return (1);
|
||||
else if (map->next->next)
|
||||
return (1);
|
||||
else if (map2)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
ft_dl_clear(&map, free);
|
||||
return (0);
|
||||
}
|
||||
26
libft/tests/ft_list/dl_tests/tests_dlist_new.c
Normal file
26
libft/tests/ft_list/dl_tests/tests_dlist_new.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_new.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:05:52 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 17:06:38 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_new(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
|
||||
list = ft_dl_new();
|
||||
if (!list)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
115
libft/tests/ft_list/dl_tests/tests_dlist_push.c
Normal file
115
libft/tests/ft_list/dl_tests/tests_dlist_push.c
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_push.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:07:52 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 17:07:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_pop(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data1;
|
||||
int *data2;
|
||||
int *ret;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data1, (void **)&data2);
|
||||
ret = ft_dl_pop(&list);
|
||||
if (!list)
|
||||
return (1);
|
||||
else if (ret != data1)
|
||||
return (2);
|
||||
ret = ft_dl_pop(&list);
|
||||
if (ret != data2)
|
||||
return (3);
|
||||
if (list)
|
||||
return (4);
|
||||
ret = ft_dl_pop(&list);
|
||||
if (ret)
|
||||
return (5);
|
||||
ret = ft_dl_pop(NULL);
|
||||
if (ret)
|
||||
return (6);
|
||||
return (free(data1), free(data2), 0);
|
||||
}
|
||||
|
||||
int t_dl_pop_back(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data1;
|
||||
int *data2;
|
||||
int *data3;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data1, (void **)&data2);
|
||||
data3 = ft_dl_pop_back(&list);
|
||||
if (!list)
|
||||
return (1);
|
||||
else if (data3 != data2)
|
||||
return (1);
|
||||
data3 = ft_dl_pop_back(&list);
|
||||
if (list)
|
||||
return (1);
|
||||
else if (data3 != data1)
|
||||
return (1);
|
||||
data3 = ft_dl_pop_back(NULL);
|
||||
if (data3)
|
||||
return (1);
|
||||
data3 = ft_dl_pop_back(&list);
|
||||
if (data3)
|
||||
return (1);
|
||||
free(data1);
|
||||
free(data2);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_push(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data1;
|
||||
|
||||
data1 = malloc(sizeof(int));
|
||||
*data1 = 42;
|
||||
list = NULL;
|
||||
ft_dl_push(&list, data1);
|
||||
if (!list)
|
||||
return (1);
|
||||
else if (list->data != data1)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_push_back(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data1;
|
||||
int *data2;
|
||||
int *data3;
|
||||
|
||||
data1 = malloc(sizeof(int));
|
||||
*data1 = 42;
|
||||
list = NULL;
|
||||
data2 = malloc(sizeof(int));
|
||||
*data2 = 21;
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 63;
|
||||
ft_dl_push_back(&list, data1);
|
||||
ft_dl_push_back(&list, data2);
|
||||
ft_dl_push_back(&list, data3);
|
||||
if (ft_dl_size(list) != 3)
|
||||
return (1);
|
||||
else if (list->data != data1 || list->next->data != data2 || \
|
||||
list->next->next->data != data3)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
41
libft/tests/ft_list/dl_tests/tests_dlist_rev.c
Normal file
41
libft/tests/ft_list/dl_tests/tests_dlist_rev.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_rev.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:08:41 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 17:08:46 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_rev(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data1;
|
||||
int *data2;
|
||||
int *original_data1;
|
||||
int *original_data2;
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data1, (void **)&data2);
|
||||
original_data1 = data1;
|
||||
original_data2 = data2;
|
||||
ft_dl_rev(&list);
|
||||
if (ft_dl_size(list) != 2)
|
||||
return (1);
|
||||
else if (list->data != original_data2 || list->next->data != original_data1)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
if (ft_dl_rev(NULL))
|
||||
return (1);
|
||||
list = NULL;
|
||||
if (ft_dl_rev(&list))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
59
libft/tests/ft_list/dl_tests/tests_dlist_sizers.c
Normal file
59
libft/tests/ft_list/dl_tests/tests_dlist_sizers.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_sizers.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:09:18 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 11:48:33 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_size(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data1;
|
||||
int *data2;
|
||||
size_t size_ret[3];
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data1, (void **)&data2);
|
||||
size_ret[0] = ft_dl_size(NULL);
|
||||
size_ret[1] = ft_dl_size(list->next);
|
||||
size_ret[2] = ft_dl_size(list);
|
||||
if (size_ret[0] != 0)
|
||||
return (1);
|
||||
else if (size_ret[1] != 1)
|
||||
return (1);
|
||||
else if (size_ret[2] != 2)
|
||||
return (1);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_dl_size_of_data(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
int *data1;
|
||||
int *data2;
|
||||
size_t size_ret[3];
|
||||
|
||||
create_2elem_dlist(&list, (void **)&data1, (void **)&data2);
|
||||
size_ret[0] = ft_dl_size_of_data(NULL, is42);
|
||||
size_ret[1] = ft_dl_size_of_data(list->next, is42);
|
||||
size_ret[2] = ft_dl_size_of_data(list, is42);
|
||||
if (size_ret[0] != 0)
|
||||
return (1);
|
||||
else if (size_ret[1] != 0)
|
||||
return (2);
|
||||
else if (size_ret[2] != 1)
|
||||
return (3);
|
||||
ft_dl_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
44
libft/tests/ft_list/dl_tests/tests_dlist_subrange.c
Normal file
44
libft/tests/ft_list/dl_tests/tests_dlist_subrange.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_dlist_subrange.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 17:10:08 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 17:10:45 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_dl_subrange(void)
|
||||
{
|
||||
t_dlist *list;
|
||||
t_dlist *sub;
|
||||
int *data1;
|
||||
int *data2;
|
||||
int *data3;
|
||||
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 63;
|
||||
create_2elem_dlist(&list, (void **)&data1, (void **)&data2);
|
||||
ft_dl_push_back(&list, data3);
|
||||
sub = ft_dl_subrange(list, list->next);
|
||||
if (ft_dl_size(sub) != 1 || sub->data != data1)
|
||||
return (1);
|
||||
ft_dl_clear(&sub, NULL);
|
||||
sub = ft_dl_subrange(list, list->next->next);
|
||||
if (ft_dl_size(sub) != 2 || sub->data != data1 || \
|
||||
sub->next->data != data2 || ft_dl_clear(&sub, NULL), 0)
|
||||
return (2);
|
||||
if (ft_dl_subrange(NULL, NULL))
|
||||
return (3);
|
||||
sub = ft_dl_subrange(list, list);
|
||||
if (ft_dl_size(sub) != 1 || sub->data != data1)
|
||||
return (4);
|
||||
return (ft_dl_clear(&sub, NULL), ft_dl_clear(&list, free), 0);
|
||||
}
|
||||
43
libft/tests/ft_list/ll_tests/ll_list_tests.c
Normal file
43
libft/tests/ft_list/ll_tests/ll_list_tests.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ll_list_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/12 13:17:51 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 12:11:12 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/tests.h"
|
||||
#include "tests/ll_tests.h"
|
||||
|
||||
int tests_linked_list_all(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test test[] = {
|
||||
{"add_front", t_ll_add_front}, {"add_back",
|
||||
t_ll_add_back}, {"apply", t_ll_apply}, {
|
||||
"apply_range", t_ll_apply_range}, {
|
||||
"apply_range_node", t_ll_apply_range_node}, {
|
||||
"clear", t_ll_clear}, {"create",
|
||||
t_ll_create}, {"copy_node", t_ll_copy_node},
|
||||
{"copy_list", t_ll_copy_list}, {"delone",
|
||||
t_ll_delone}, {"delete_range", t_ll_delete_range},
|
||||
{"find", t_ll_find}, {"get_datas",
|
||||
t_ll_get_datas}, {"get_nodes", t_ll_get_nodes}, {
|
||||
"end", t_ll_end}, {"at", t_ll_at}, {
|
||||
"map", t_ll_map}, {"new", t_ll_new}, {
|
||||
"push", t_ll_push}, {"push_back",
|
||||
t_ll_push_back}, {"pop", t_ll_pop}, {
|
||||
"pop_back", t_ll_pop_back}, {"rev", t_ll_rev},
|
||||
{"size", t_ll_size}, {"size_match",
|
||||
t_ll_size_match}, {"subrange", t_ll_subrange},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
collect = 0;
|
||||
run_test(test, &collect);
|
||||
return (collect);
|
||||
}
|
||||
26
libft/tests/ft_list/ll_tests/ll_tests_utils.c
Normal file
26
libft/tests/ft_list/ll_tests/ll_tests_utils.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ll_test_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 11:08:48 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 14:27:13 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void create_2elem_list(t_list **list, void **data1, void **data2)
|
||||
{
|
||||
*data1 = malloc(sizeof(int));
|
||||
*data2 = malloc(sizeof(int));
|
||||
*(int *)*data1 = 42;
|
||||
*(int *)*data2 = 21;
|
||||
*list = NULL;
|
||||
ft_ll_push(list, *data1);
|
||||
ft_ll_push_back(list, *data2);
|
||||
}
|
||||
65
libft/tests/ft_list/ll_tests/tests_list_add.c
Normal file
65
libft/tests/ft_list/ll_tests/tests_list_add.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_add.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:15:52 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:46:39 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
list = NULL;
|
||||
ft_ll_add_front(&list, ft_ll_create(data2)); // (21)-> NULL
|
||||
ft_ll_add_front(&list, ft_ll_create(data)); // (42)-> (21)-> NULL
|
||||
---
|
||||
ft_ll_add_front(NULL, list); // null resiliency
|
||||
ft_ll_clear(&list, free);
|
||||
*/
|
||||
|
||||
int t_ll_add_front(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
data2 = malloc(sizeof(int));
|
||||
*data2 = 21;
|
||||
list = NULL;
|
||||
ft_ll_add_front(&list, ft_ll_create(data2));
|
||||
ft_ll_add_front(&list, ft_ll_create(data));
|
||||
if (!list || list->data != data || !list->next
|
||||
|| list->next->data != data2 || list->next->next)
|
||||
return (1);
|
||||
ft_ll_add_front(NULL, list);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_add_back(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
data2 = malloc(sizeof(int));
|
||||
*data2 = 21;
|
||||
list = ft_ll_create(data);
|
||||
ft_ll_add_back(&list, ft_ll_create(data2));
|
||||
if (!list || list->data != data || !list->next)
|
||||
return (1);
|
||||
else if (list->next->data != data2 || list->next->next)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
92
libft/tests/ft_list/ll_tests/tests_list_apply.c
Normal file
92
libft/tests/ft_list/ll_tests/tests_list_apply.c
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_apply.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:18:39 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 11:47:07 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/ll_tests.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void lnode_add42(t_list *node)
|
||||
{
|
||||
*(int *)node->data += 42;
|
||||
}
|
||||
|
||||
int t_ll_apply(void)
|
||||
{
|
||||
const int data3 = 63;
|
||||
const int data4 = 84;
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
ft_ll_apply(list, add42);
|
||||
if (!list || !list->next || list->next->next
|
||||
|| *(int *)list->data != data4 || *(int *)list->next->data != data3)
|
||||
return (1);
|
||||
ft_ll_apply(list, NULL);
|
||||
if (!list || !list->next || list->next->next
|
||||
|| *(int *)list->data != data4 || *(int *)list->next->data != data3)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_apply_range(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
const int data3 = 84;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
ft_ll_apply_range(list, list->next, add42);
|
||||
if (*(int *)list->data != data3)
|
||||
return (1);
|
||||
else if (ft_ll_size(list) != 2)
|
||||
return (1);
|
||||
else if (*(int *)list->next->data != 21)
|
||||
return (1);
|
||||
ft_ll_apply_range(list, list->next, NULL);
|
||||
if (ft_ll_size(list) != 2)
|
||||
return (1);
|
||||
else if (*(int *)list->data != data3)
|
||||
return (1);
|
||||
else if (*(int *)list->next->data != 21)
|
||||
return (1);
|
||||
ft_ll_apply_range(NULL, NULL, add42);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_apply_range_node(void)
|
||||
{
|
||||
const int data3 = 84;
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
ft_ll_apply_range_node(list, list->next, lnode_add42);
|
||||
if (*(int *)list->data != data3 || !list->next
|
||||
|| *(int *)list->next->data != 21 || list->next->next)
|
||||
return (1);
|
||||
ft_ll_apply_range_node(list, list->next, NULL);
|
||||
if (*(int *)list->data != data3 || !list->next
|
||||
|| *(int *)list->next->data != 21 || list->next->next)
|
||||
return (1);
|
||||
ft_ll_apply_range_node(NULL, NULL, lnode_add42);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
30
libft/tests/ft_list/ll_tests/tests_list_clear.c
Normal file
30
libft/tests/ft_list/ll_tests/tests_list_clear.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_listclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:21:50 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:22:49 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "tests/ll_tests.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_clear(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
list = ft_ll_create(data);
|
||||
ft_ll_clear(&list, NULL);
|
||||
list = ft_ll_create(data);
|
||||
ft_ll_clear(&list, free);
|
||||
ft_ll_clear(NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
62
libft/tests/ft_list/ll_tests/tests_list_copy.c
Normal file
62
libft/tests/ft_list/ll_tests/tests_list_copy.c
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_listcopy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:24:02 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:25:18 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/ll_tests.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_copy_node(void)
|
||||
{
|
||||
t_list *list;
|
||||
t_list *copy;
|
||||
int *data;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
list = ft_ll_create(data);
|
||||
copy = ft_ll_copy_node(list);
|
||||
if (!copy)
|
||||
return (1);
|
||||
else if (copy->data != list->data)
|
||||
return (1);
|
||||
else if (copy->next != list->next)
|
||||
return (1);
|
||||
free(data);
|
||||
free(list);
|
||||
free(copy);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_copy_list(void)
|
||||
{
|
||||
t_list *list;
|
||||
t_list *copy;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
copy = ft_ll_copy_list(list);
|
||||
if (!copy)
|
||||
return (1);
|
||||
else if (copy->data != list->data)
|
||||
return (1);
|
||||
else if (!copy->next)
|
||||
return (1);
|
||||
else if (copy->next->data != list->next->data)
|
||||
return (1);
|
||||
else if (copy->next->next)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
ft_ll_clear(©, NULL);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_list/ll_tests/tests_list_create.c
Normal file
34
libft/tests/ft_list/ll_tests/tests_list_create.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_listcreate.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:23:08 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:23:34 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "tests/ll_tests.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_create(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
list = ft_ll_create(data);
|
||||
if (!list)
|
||||
return (1);
|
||||
else if (list->data != data)
|
||||
return (1);
|
||||
else if (list->next)
|
||||
return (1);
|
||||
free(data);
|
||||
free(list);
|
||||
return (0);
|
||||
}
|
||||
81
libft/tests/ft_list/ll_tests/tests_list_deletors.c
Normal file
81
libft/tests/ft_list/ll_tests/tests_list_deletors.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_listdeletors.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:25:58 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:26:50 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// ft_ll_delone(NULL, NULL); // null resiliency
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_delone(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
list = ft_ll_create(data);
|
||||
ft_ll_delone(list, NULL);
|
||||
list = ft_ll_create(data);
|
||||
ft_ll_delone(list, free);
|
||||
ft_ll_delone(NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
ft_ll_add_back(&list, ft_ll_create(data2)); // (42)-> (21)-> NULL
|
||||
list2 = list->next;
|
||||
nb_deleted = ft_ll_delete_range(list, list->next, NULL);
|
||||
// (42)-> (21)-> NULL
|
||||
nb_deleted2 = ft_ll_delete_range(list, list->next, free);
|
||||
// (21)-> NULL
|
||||
// we use list2 to check if the list is still valid
|
||||
// list was destroyed by ft_ll_delete_range
|
||||
---
|
||||
ft_ll_clear(&list2, free); // NULL
|
||||
---
|
||||
nb_deleted = ft_ll_delete_range(NULL, NULL, free); // null resiliency
|
||||
---
|
||||
list = ft_ll_create(data); // (42)-> NULL
|
||||
nb_deleted = ft_ll_delete_range(list, NULL, free); // NULL
|
||||
---
|
||||
|
||||
*/
|
||||
|
||||
int t_ll_delete_range(void)
|
||||
{
|
||||
t_list *list;
|
||||
t_list *list2;
|
||||
int *data;
|
||||
int *data2;
|
||||
int nb_del[2];
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
list2 = list->next;
|
||||
nb_del[0] = ft_ll_delete_range(list, list->next, NULL);
|
||||
nb_del[1] = ft_ll_delete_range(list, list->next, free);
|
||||
if ((nb_del[0] != 0 || nb_del[1] != 1) || \
|
||||
(list2->data != data2 || list2->next))
|
||||
return (__LINE__);
|
||||
ft_ll_clear(&list2, free);
|
||||
nb_del[0] = ft_ll_delete_range(NULL, NULL, free);
|
||||
if (nb_del[0] != 0)
|
||||
return (__LINE__);
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
list = ft_ll_create(data);
|
||||
nb_del[0] = ft_ll_delete_range(list, NULL, free);
|
||||
if (nb_del[0] != 1)
|
||||
return (__LINE__);
|
||||
return (0);
|
||||
}
|
||||
46
libft/tests/ft_list/ll_tests/tests_list_find.c
Normal file
46
libft/tests/ft_list/ll_tests/tests_list_find.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_find.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:27:50 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 11:47:52 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_find(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
int *data3;
|
||||
void *found;
|
||||
|
||||
data3 = malloc(sizeof(int));
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
found = ft_ll_find(list, data2, NULL);
|
||||
if (!found || *(int *)found != *data2)
|
||||
return (1);
|
||||
*data3 = 63;
|
||||
found = ft_ll_find(list, data3, cmp_int);
|
||||
if (found)
|
||||
return (2);
|
||||
found = ft_ll_find(NULL, data2, NULL);
|
||||
if (found)
|
||||
return (3);
|
||||
*data3 = 42;
|
||||
found = ft_ll_find(list, data3, cmp_int);
|
||||
if (!found || *(int *)found != *data)
|
||||
return (4);
|
||||
ft_ll_clear(&list, free);
|
||||
free(data3);
|
||||
return (0);
|
||||
}
|
||||
54
libft/tests/ft_list/ll_tests/tests_list_get.c
Normal file
54
libft/tests/ft_list/ll_tests/tests_list_get.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_listget.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:32:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:33:24 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_get_datas(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
void **datas;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
datas = ft_ll_get_datas(list);
|
||||
if (!datas || datas[2] || datas[0] != data || \
|
||||
datas[1] != data2)
|
||||
return (1);
|
||||
if (ft_ll_get_datas(NULL))
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
free(datas);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_get_nodes(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
t_list **nodes;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
nodes = ft_ll_get_nodes(list);
|
||||
if (!nodes || nodes[2] || nodes[0] != list || \
|
||||
nodes[1] != list->next)
|
||||
return (1);
|
||||
if (ft_ll_get_nodes(NULL))
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
free(nodes);
|
||||
return (0);
|
||||
}
|
||||
59
libft/tests/ft_list/ll_tests/tests_list_iterators.c
Normal file
59
libft/tests/ft_list/ll_tests/tests_list_iterators.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_listend.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:33:48 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:34:43 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_end(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
t_list *last;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
last = ft_ll_end(list);
|
||||
if (!last)
|
||||
return (1);
|
||||
else if (last->data != data2)
|
||||
return (1);
|
||||
else if (last->next)
|
||||
return (1);
|
||||
last = ft_ll_end(NULL);
|
||||
if (last)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_at(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
t_list *at;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
at = ft_ll_at(list, 1);
|
||||
if (!at || at->data != data2 || at->next)
|
||||
return (1);
|
||||
at = ft_ll_at(list, 456);
|
||||
if (at)
|
||||
return (1);
|
||||
at = ft_ll_at(NULL, 0);
|
||||
if (at)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
43
libft/tests/ft_list/ll_tests/tests_list_map.c
Normal file
43
libft/tests/ft_list/ll_tests/tests_list_map.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:36:51 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 11:44:57 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_map(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
t_list *map;
|
||||
t_list *map_err[3];
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
map = ft_ll_map(list, add42_ret, free);
|
||||
map_err[0] = ft_ll_map(list, NULL, free);
|
||||
map_err[1] = ft_ll_map(NULL, add42_ret, free);
|
||||
map_err[2] = ft_ll_map(list, add42_ret, NULL);
|
||||
if (!map || *(int *)map->data != 84 || !map->next)
|
||||
return (1);
|
||||
else if (*(int *)map->next->data != 63)
|
||||
return (1);
|
||||
else if (map->next->next)
|
||||
return (1);
|
||||
else if (map_err[0] || map_err[1] || map_err[2])
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
ft_ll_clear(&map, free);
|
||||
return (0);
|
||||
}
|
||||
26
libft/tests/ft_list/ll_tests/tests_list_new.c
Normal file
26
libft/tests/ft_list/ll_tests/tests_list_new.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_new.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:37:19 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:39:43 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_new(void)
|
||||
{
|
||||
t_list *list;
|
||||
|
||||
list = ft_ll_new();
|
||||
if (!list)
|
||||
return (1);
|
||||
free(list);
|
||||
return (0);
|
||||
}
|
||||
134
libft/tests/ft_list/ll_tests/tests_list_push.c
Normal file
134
libft/tests/ft_list/ll_tests/tests_list_push.c
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_push.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:37:47 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:39:15 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_push(void)
|
||||
{
|
||||
t_list *list;
|
||||
t_list *list_rep1;
|
||||
t_list *list_rep2;
|
||||
const int data[][1] = {
|
||||
{42},
|
||||
{21}
|
||||
};
|
||||
|
||||
list = NULL;
|
||||
list_rep1 = ft_ll_push(&list, &data[0]);
|
||||
list_rep2 = ft_ll_push(&list, &data[1]);
|
||||
if (!list || !list_rep1 || !list_rep2)
|
||||
return (1);
|
||||
else if (list != list_rep2)
|
||||
return (1);
|
||||
else if (list->next != list_rep1)
|
||||
return (1);
|
||||
else if (ft_ll_size(list) != 2)
|
||||
return (1);
|
||||
else if (list->data != &data[1] || list->next->data != &data[0])
|
||||
return (1);
|
||||
ft_ll_clear(&list, NULL);
|
||||
ft_ll_push(NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_push_back(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
data = malloc(sizeof(int));
|
||||
*data = 42;
|
||||
data2 = malloc(sizeof(int));
|
||||
*data2 = 21;
|
||||
list = NULL;
|
||||
ft_ll_push_back(&list, data);
|
||||
ft_ll_push_back(&list, data2);
|
||||
if (ft_ll_size(list) != 2)
|
||||
return (1);
|
||||
else if (list->data != data)
|
||||
return (1);
|
||||
else if (list->next->data != data2)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
ft_ll_push_back(NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_pop(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
void *pop;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
pop = ft_ll_pop(&list);
|
||||
if (!list || ft_ll_size(list) != 1)
|
||||
return (1);
|
||||
else if (list->data != data2)
|
||||
return (1);
|
||||
else if (pop != data)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
free(pop);
|
||||
if (ft_ll_pop(&list) || ft_ll_pop(NULL))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2); // (42)-> (21)-> NULL
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 63;
|
||||
ft_ll_push(&list, data3); // (63)-> (42)-> (21)-> NULL
|
||||
pop = ft_ll_pop_back(&list); // 21 : (63)-> (42)-> NULL
|
||||
if (ft_ll_size(list) != 2)
|
||||
return (1);
|
||||
else if (list->data != data3)
|
||||
return (1);
|
||||
else if (list->next->data != data)
|
||||
return (1);
|
||||
else if (pop != data2)
|
||||
return (1);
|
||||
pop = ft_ll_pop_back(&list); // 42 : (63)-> NULL
|
||||
|
||||
*/
|
||||
int t_ll_pop_back(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
int *data3;
|
||||
void *pop;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
data3 = malloc(sizeof(int));
|
||||
*data3 = 63;
|
||||
ft_ll_push(&list, data3);
|
||||
pop = ft_ll_pop_back(&list);
|
||||
if (ft_ll_size(list) != 2)
|
||||
return (1);
|
||||
else if (list->data != data3 || list->next->data != data || pop != data2)
|
||||
return (1);
|
||||
pop = ft_ll_pop_back(&list);
|
||||
if (ft_ll_size(list) != 1 || list->data != data3 || pop != data)
|
||||
return (1);
|
||||
pop = ft_ll_pop_back(&list);
|
||||
if (list || pop != data3 || ft_ll_size(list) != 0 || \
|
||||
ft_ll_pop_back(&list))
|
||||
return (1);
|
||||
return (free(data), free(data2), free(data3), 0);
|
||||
}
|
||||
39
libft/tests/ft_list/ll_tests/tests_list_rev.c
Normal file
39
libft/tests/ft_list/ll_tests/tests_list_rev.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_rev.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:40:24 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:41:32 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_rev(void)
|
||||
{
|
||||
t_list *list;
|
||||
t_list *rev;
|
||||
int *data;
|
||||
int *data2;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
rev = ft_ll_rev(&list);
|
||||
if (ft_ll_size(list) != 2)
|
||||
return (1);
|
||||
else if (rev->data != data2)
|
||||
return (1);
|
||||
else if (rev->next->data != data)
|
||||
return (1);
|
||||
ft_ll_clear(&rev, free);
|
||||
rev = NULL;
|
||||
rev = ft_ll_rev(NULL);
|
||||
if (rev || ft_ll_rev(&rev))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
59
libft/tests/ft_list/ll_tests/tests_list_sizers.c
Normal file
59
libft/tests/ft_list/ll_tests/tests_list_sizers.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_sizers.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:43:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 11:46:41 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int t_ll_size(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
size_t size_ret[3];
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
size_ret[0] = ft_ll_size(NULL);
|
||||
size_ret[1] = ft_ll_size(list->next);
|
||||
size_ret[2] = ft_ll_size(list);
|
||||
if (size_ret[0] != 0)
|
||||
return (1);
|
||||
if (size_ret[1] != 1)
|
||||
return (1);
|
||||
if (size_ret[2] != 2)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int t_ll_size_match(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
size_t size_ret[3];
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
size_ret[0] = ft_ll_size_match(NULL, is42);
|
||||
size_ret[1] = ft_ll_size_match(list, is42);
|
||||
size_ret[2] = ft_ll_size_match(list->next, is42);
|
||||
if (size_ret[0] != 0)
|
||||
return (1);
|
||||
if (size_ret[1] != 1)
|
||||
return (1);
|
||||
if (size_ret[2] != 0)
|
||||
return (1);
|
||||
ft_ll_clear(&list, free);
|
||||
return (0);
|
||||
}
|
||||
53
libft/tests/ft_list/ll_tests/tests_list_subrange.c
Normal file
53
libft/tests/ft_list/ll_tests/tests_list_subrange.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_list_subrange.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 16:44:51 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 16:46:04 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_list.h"
|
||||
#include "ft_list_types.h"
|
||||
#include "tests/lists_test_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
ft_ll_push(&list, data); // (42)-> NULL
|
||||
ft_ll_push(&list, data2); // (21)-> (42)-> NULL
|
||||
sub = ft_ll_subrange(list, list->next); // (21)-> NULL
|
||||
sub = ft_ll_subrange(list, NULL); // (21)-> (42)-> NULL
|
||||
sub = ft_ll_subrange(list, (const t_list *)data2); // (21)-> (42)-> NULL
|
||||
*/
|
||||
|
||||
int t_ll_subrange(void)
|
||||
{
|
||||
t_list *list;
|
||||
int *data;
|
||||
int *data2;
|
||||
t_list *sub;
|
||||
|
||||
create_2elem_list(&list, (void **)&data, (void **)&data2);
|
||||
ft_ll_rev(&list);
|
||||
sub = ft_ll_subrange(list, list->next);
|
||||
if (ft_ll_size(sub) != 1 || sub->data != data2)
|
||||
return (1);
|
||||
ft_ll_clear(&sub, NULL);
|
||||
sub = ft_ll_subrange(list, NULL);
|
||||
if (ft_ll_size(sub) != 2 || sub->data != data2 || sub->next->data != data)
|
||||
return (2);
|
||||
ft_ll_clear(&sub, NULL);
|
||||
sub = ft_ll_subrange(list, (const t_list *)data2);
|
||||
if (ft_ll_size(sub) != 2 || sub->data != data2 || sub->next->data != data)
|
||||
return (3);
|
||||
ft_ll_clear(&sub, NULL);
|
||||
if (ft_ll_subrange(NULL, NULL))
|
||||
return (4);
|
||||
sub = ft_ll_subrange(list, list);
|
||||
if (ft_ll_size(sub) != 1 || sub->data != data2)
|
||||
return (5);
|
||||
return (ft_ll_clear(&sub, NULL), ft_ll_clear(&list, free), 0);
|
||||
}
|
||||
39
libft/tests/ft_map/map_tests.c
Normal file
39
libft/tests/ft_map/map_tests.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* map_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/11 18:27:46 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/07 14:59:37 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/tests.h"
|
||||
#include "tests/map_tests.h"
|
||||
|
||||
// see with --leak-check=full
|
||||
int tests_map(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test test[] = {
|
||||
{"create", test_map_create},
|
||||
{"destroy", test_map_destroy}, // here
|
||||
{"destroy_free", test_map_destroy_free},
|
||||
{"clear", test_map_clear}, // here
|
||||
{"set", test_map_set},
|
||||
{"set_cmp", test_map_set_cmp},
|
||||
{"set_hash", test_map_set_hash},
|
||||
{"get", test_map_get},
|
||||
{"size", test_map_size},
|
||||
{"capacity", test_map_capacity},
|
||||
{"remove", test_map_remove}, // here
|
||||
{"hash", test_map_hash},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
collect = 0;
|
||||
run_test(test, &collect);
|
||||
return (collect);
|
||||
}
|
||||
27
libft/tests/ft_map/tests_map_cappacity.c
Normal file
27
libft/tests/ft_map/tests_map_cappacity.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_cappacity.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:16:49 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/01 12:03:26 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_map_types.h"
|
||||
|
||||
int test_map_capacity(void)
|
||||
{
|
||||
t_map *map;
|
||||
size_t ret;
|
||||
|
||||
map = ft_map_create(10);
|
||||
ret = ft_map_capacity(map);
|
||||
if (ret != 10)
|
||||
return (1);
|
||||
ft_map_destroy(map);
|
||||
return (0);
|
||||
}
|
||||
32
libft/tests/ft_map/tests_map_clear.c
Normal file
32
libft/tests/ft_map/tests_map_clear.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_clear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:11:13 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/01 12:41:04 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_map_types.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
// clear the map and check if the value is still present
|
||||
// try to double clear the map
|
||||
|
||||
int test_map_clear(void)
|
||||
{
|
||||
t_map *map;
|
||||
|
||||
map = ft_map_create(10);
|
||||
ft_map_set(map, "key", "value", ft_strlen("key"));
|
||||
ft_map_clear(map);
|
||||
if (ft_map_get(map, "key", ft_strlen("key")))
|
||||
return (1);
|
||||
ft_map_clear(map);
|
||||
ft_map_destroy(map);
|
||||
return (0);
|
||||
}
|
||||
25
libft/tests/ft_map/tests_map_create.c
Normal file
25
libft/tests/ft_map/tests_map_create.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_create.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:07:38 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/19 18:07:42 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_map_types.h"
|
||||
|
||||
int test_map_create(void)
|
||||
{
|
||||
t_map *map;
|
||||
|
||||
map = ft_map_create(10);
|
||||
if (!map)
|
||||
return (1);
|
||||
ft_map_destroy(map);
|
||||
return (0);
|
||||
}
|
||||
48
libft/tests/ft_map/tests_map_destroy.c
Normal file
48
libft/tests/ft_map/tests_map_destroy.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_destroy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:08:04 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/01 12:07:40 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_string.h"
|
||||
#include "ft_map_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
// check valgrind for no memory leak
|
||||
int test_map_destroy(void)
|
||||
{
|
||||
t_map *map;
|
||||
|
||||
map = ft_map_create(10);
|
||||
ft_map_destroy(map);
|
||||
return (0);
|
||||
}
|
||||
|
||||
// accessing to key[0] and value[0] after the call to check
|
||||
// that no free occured on the data at first call
|
||||
int test_map_destroy_free(void)
|
||||
{
|
||||
t_map *map;
|
||||
char *key;
|
||||
char *value;
|
||||
|
||||
key = ft_strdup("keys");
|
||||
value = ft_strdup("values");
|
||||
map = ft_map_create(10);
|
||||
ft_map_set(map, key, value, ft_strlen(key));
|
||||
ft_map_destroy_free(map, NULL);
|
||||
key[0] = 'k';
|
||||
value[0] = 'v';
|
||||
map = ft_map_create(15);
|
||||
ft_map_set(map, key, value, ft_strlen(key));
|
||||
ft_map_destroy_free(map, free);
|
||||
free(key);
|
||||
return (0);
|
||||
}
|
||||
84
libft/tests/ft_map/tests_map_get.c
Normal file
84
libft/tests/ft_map/tests_map_get.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_get.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:14:47 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/23 18:28:31 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
// search for a non existing key
|
||||
ret = ft_map_get(map, "key2", strlen("key2") + 1);
|
||||
---
|
||||
// search for a non existing key in a full map
|
||||
map = ft_map_create(1);
|
||||
*/
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_map_types.h"
|
||||
#include "ft_string.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int test_map_get_ultra_small(void)
|
||||
{
|
||||
char *str[2];
|
||||
t_map *map;
|
||||
void *ret;
|
||||
|
||||
str[0] = ft_strdup("value");
|
||||
str[1] = ft_strdup("value2");
|
||||
map = ft_map_create(1);
|
||||
ft_map_set(map, "key", str[0], ft_strlen("key"));
|
||||
ft_map_set(map, "key2", str[1], ft_strlen("key"));
|
||||
ret = ft_map_get(map, "key", ft_strlen("key"));
|
||||
if (!ret)
|
||||
return (1);
|
||||
else if (ft_strcmp((char *)ret, "value"))
|
||||
return (2);
|
||||
ret = ft_map_get(map, "key2", ft_strlen("key2"));
|
||||
if (!ret)
|
||||
return (3);
|
||||
else if (ft_strcmp((char *)ret, "value2"))
|
||||
return (4);
|
||||
ft_map_destroy_free(map, free);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_map_normal(void)
|
||||
{
|
||||
char *str;
|
||||
t_map *map;
|
||||
void *ret;
|
||||
|
||||
str = ft_strdup("value");
|
||||
map = ft_map_create(10);
|
||||
ft_map_set(map, "key", str, ft_strlen("key"));
|
||||
ret = ft_map_get(map, "key", ft_strlen("key"));
|
||||
if (!ret)
|
||||
return (1);
|
||||
else if (ft_strcmp((char *)ret, "value"))
|
||||
return (2);
|
||||
ret = ft_map_get(map, "key2", ft_strlen("key2"));
|
||||
if (ret)
|
||||
return (3);
|
||||
ft_map_destroy(map);
|
||||
free(str);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_map_get(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = test_map_get_ultra_small();
|
||||
if (ret != 0)
|
||||
return (ret + 10 * 0);
|
||||
ret = test_map_normal();
|
||||
if (ret != 0)
|
||||
return (ret + 10 * 1);
|
||||
return (0);
|
||||
}
|
||||
42
libft/tests/ft_map/tests_map_hash.c
Normal file
42
libft/tests/ft_map/tests_map_hash.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_hash.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:21:33 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/01 12:24:06 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_defs.h"
|
||||
#include "ft_map.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
// we dont really test the hash function, we just test that
|
||||
// it doesn't overflow our map
|
||||
|
||||
int test_map_hash(void)
|
||||
{
|
||||
size_t ret;
|
||||
size_t ret2;
|
||||
|
||||
ret = ft_hash_djb2("key", ft_strlen("key"));
|
||||
ret2 = ft_hash_djb2("key2", ft_strlen("key2"));
|
||||
if (ret == ret2)
|
||||
return (1);
|
||||
ret = ft_hash_sdbm("key", ft_strlen("key"));
|
||||
ret2 = ft_hash_sdbm("key2", ft_strlen("key2"));
|
||||
if (ret == ret2)
|
||||
return (1);
|
||||
ret = ft_hash_fnv1a("key", ft_strlen("key"));
|
||||
ret2 = ft_hash_fnv1a("key2", ft_strlen("key2"));
|
||||
if (ret == ret2)
|
||||
return (1);
|
||||
ret = ft_hash_dummy("key", ft_strlen("key"));
|
||||
ret2 = ft_hash_dummy("key2", ft_strlen("key2"));
|
||||
if (ret == ret2)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
80
libft/tests/ft_map/tests_map_remove.c
Normal file
80
libft/tests/ft_map/tests_map_remove.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_remove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:18:53 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/23 18:31:50 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_string.h"
|
||||
#include "ft_map_types.h"
|
||||
#include "ft_string.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static int test_map_remove_normal(void)
|
||||
{
|
||||
char *str;
|
||||
void *ret;
|
||||
t_map *map;
|
||||
|
||||
str = ft_strdup("value");
|
||||
map = ft_map_create(10);
|
||||
ft_map_set(map, "key", str, ft_strlen("key"));
|
||||
ret = ft_map_remove(map, "key", ft_strlen("key"));
|
||||
if (!ret)
|
||||
return (1);
|
||||
else if (ret != str)
|
||||
return (2);
|
||||
ret = ft_map_remove(map, "key2", ft_strlen("key2"));
|
||||
if (ret)
|
||||
return (3);
|
||||
ft_map_destroy(map);
|
||||
free(str);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test_map_remove_colision(void)
|
||||
{
|
||||
const char *keys[] = {"key", "key2", "key3", "key4", NULL};
|
||||
const char *str[] = {
|
||||
ft_strdup("value"), ft_strdup("value2"), ft_strdup("value3"),
|
||||
ft_strdup("value4"), NULL};
|
||||
t_map *map;
|
||||
int ret;
|
||||
|
||||
map = ft_map_create(1);
|
||||
ret = 0;
|
||||
while (str[ret])
|
||||
{
|
||||
ft_map_set(map, keys[ret], str[ret], ft_strlen(keys[ret]));
|
||||
ret++;
|
||||
}
|
||||
ret = 0;
|
||||
if (ft_map_remove(map, keys[2], ft_strlen(keys[2])) != str[2])
|
||||
return (1);
|
||||
if (ft_map_remove(map, keys[1], ft_strlen(keys[1])) != str[1])
|
||||
return (2);
|
||||
if (ft_map_remove(map, keys[0], ft_strlen(keys[0])) != str[0])
|
||||
return (3);
|
||||
if (ft_map_remove(map, keys[3], ft_strlen(keys[3])) != str[3])
|
||||
return (4);
|
||||
return (ft_map_destroy(map), ft_apply_2d((void **)str, free), 0);
|
||||
}
|
||||
|
||||
int test_map_remove(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = test_map_remove_normal();
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = test_map_remove_colision();
|
||||
if (ret != 0)
|
||||
return (ret + 10);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_map/tests_map_set.c
Normal file
34
libft/tests/ft_map/tests_map_set.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_set.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:12:34 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/01 12:39:24 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_map_types.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_map_set(void)
|
||||
{
|
||||
char *str;
|
||||
char *str2;
|
||||
t_map *map;
|
||||
|
||||
str = ft_strdup("value");
|
||||
str2 = ft_strdup("value2");
|
||||
map = ft_map_create(1);
|
||||
if (ft_map_set(map, "key", str, ft_strlen("key")) != true)
|
||||
return (1);
|
||||
if (ft_map_set(map, "key", str2, ft_strlen("key")) != true)
|
||||
return (1);
|
||||
ft_map_destroy(map);
|
||||
free(str);
|
||||
free(str2);
|
||||
return (0);
|
||||
}
|
||||
38
libft/tests/ft_map/tests_map_set_cmphash.c
Normal file
38
libft/tests/ft_map/tests_map_set_cmphash.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_set_cmphash.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:13:15 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/01 12:14:24 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_map_types.h"
|
||||
|
||||
int test_map_set_cmp(void)
|
||||
{
|
||||
t_map *map;
|
||||
|
||||
map = ft_map_create(10);
|
||||
ft_map_set_cmp(map, NULL);
|
||||
if (map->cmp)
|
||||
return (1);
|
||||
ft_map_destroy(map);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_map_set_hash(void)
|
||||
{
|
||||
t_map *map;
|
||||
|
||||
map = ft_map_create(10);
|
||||
ft_map_set_hash(map, NULL);
|
||||
if (map->hash)
|
||||
return (1);
|
||||
ft_map_destroy(map);
|
||||
return (0);
|
||||
}
|
||||
33
libft/tests/ft_map/tests_map_size.c
Normal file
33
libft/tests/ft_map/tests_map_size.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_map_size.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 18:15:34 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/25 22:17:17 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_map.h"
|
||||
#include "ft_map_types.h"
|
||||
#include "ft_string.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int test_map_size(void)
|
||||
{
|
||||
char *str;
|
||||
t_map *map;
|
||||
size_t ret;
|
||||
|
||||
str = ft_strdup("value");
|
||||
map = ft_map_create(10);
|
||||
ft_map_set(map, "key", str, ft_strlen("key"));
|
||||
ret = ft_map_size(map);
|
||||
if (ret != 1)
|
||||
return (1);
|
||||
ft_map_destroy(map);
|
||||
free(str);
|
||||
return (0);
|
||||
}
|
||||
37
libft/tests/ft_math/math_tests.c
Normal file
37
libft/tests/ft_math/math_tests.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* math_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:16:35 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/26 20:50:59 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/tests.h"
|
||||
#include "tests/math_tests.h"
|
||||
|
||||
int tests_math(void)
|
||||
{
|
||||
int i;
|
||||
const t_test tests[] = {
|
||||
{"abs", test_ft_abs}, {"clamp", test_ft_clamp},
|
||||
{"complex_abs", test_ft_complex_abs},
|
||||
{"complex_addl", test_ft_complex_addl},
|
||||
{"complex_mull", test_ft_complex_mull},
|
||||
{"complex_muld", test_ft_complex_muld},
|
||||
{"range", test_ft_range}, {"range_f", test_ft_range_f},
|
||||
{"range_d", test_ft_range_d}, {"log", test_ft_log},
|
||||
{"llogof", test_ft_llogof}, {"ullogof", test_ft_ullogof},
|
||||
{"logof", test_ft_logof}, {"min", test_ft_min},
|
||||
{"max", test_ft_max}, {"pow", test_ft_pow}, {"round", test_ft_round},
|
||||
{"sqrt", test_ft_sqrt}, {"clamp_f", test_ft_clamp_f},
|
||||
{"clamp_d", test_ft_clamp_d}, {"align", test_ft_align},
|
||||
{"align_2", test_ft_align_2}, {NULL, NULL}};
|
||||
|
||||
i = 0;
|
||||
run_test(tests, &i);
|
||||
return (i);
|
||||
}
|
||||
29
libft/tests/ft_math/tests_abs.c
Normal file
29
libft/tests/ft_math/tests_abs.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_ft_abs.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:20:34 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 23:21:18 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_abs(void)
|
||||
{
|
||||
int x;
|
||||
|
||||
x = -42;
|
||||
if (ft_abs(x) != 42)
|
||||
return (1);
|
||||
x = 42;
|
||||
if (ft_abs(x) != 42)
|
||||
return (1);
|
||||
x = 0;
|
||||
if (ft_abs(x) != 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
57
libft/tests/ft_math/tests_align.c
Normal file
57
libft/tests/ft_math/tests_align.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_align.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/26 19:53:26 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/06 17:05:07 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_align_2(void)
|
||||
{
|
||||
size_t size;
|
||||
size_t result;
|
||||
|
||||
size = 42;
|
||||
result = ft_align_2(size, 4);
|
||||
if (result != 44)
|
||||
return (1);
|
||||
result = ft_align_2(size, 8);
|
||||
if (result != 48)
|
||||
return (2);
|
||||
result = ft_align_2(size, 16);
|
||||
if (result != 48)
|
||||
return (3);
|
||||
size = 275;
|
||||
result = ft_align_2(size, 4);
|
||||
if (result != 276)
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_align(void)
|
||||
{
|
||||
size_t size;
|
||||
size_t result;
|
||||
|
||||
size = 42;
|
||||
result = ft_align(size, 4);
|
||||
if (result != 44)
|
||||
return (1);
|
||||
result = ft_align(size, 8);
|
||||
if (result != 48)
|
||||
return (2);
|
||||
result = ft_align(size, 16);
|
||||
if (result != 48)
|
||||
return (3);
|
||||
size = 275;
|
||||
result = ft_align(size, 6);
|
||||
if (result != 276)
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
85
libft/tests/ft_math/tests_clamp.c
Normal file
85
libft/tests/ft_math/tests_clamp.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_clamp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:46:19 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/28 09:12:26 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_clamp(void)
|
||||
{
|
||||
const int max = 42;
|
||||
const int min = 21;
|
||||
int x;
|
||||
|
||||
x = 0;
|
||||
if (ft_clamp(x, min, max) != min)
|
||||
return (1);
|
||||
x = 21;
|
||||
if (ft_clamp(x, min, max) != min)
|
||||
return (1);
|
||||
x = 42;
|
||||
if (ft_clamp(x, min, max) != max)
|
||||
return (1);
|
||||
x = 84;
|
||||
if (ft_clamp(x, min, max) != max)
|
||||
return (1);
|
||||
x = 23;
|
||||
if (ft_clamp(x, min, max) != x)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_clamp_f(void)
|
||||
{
|
||||
const float max = 42.0;
|
||||
const float min = 21.0;
|
||||
float x;
|
||||
|
||||
x = 0;
|
||||
if (ft_clamp_f(x, min, max) != min)
|
||||
return (1);
|
||||
x = 21;
|
||||
if (ft_clamp_f(x, min, max) != min)
|
||||
return (1);
|
||||
x = 42;
|
||||
if (ft_clamp_f(x, min, max) != max)
|
||||
return (1);
|
||||
x = 84;
|
||||
if (ft_clamp_f(x, min, max) != max)
|
||||
return (1);
|
||||
x = 23;
|
||||
if (ft_clamp_f(x, min, max) != x)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_clamp_d(void)
|
||||
{
|
||||
const double max = 42.0;
|
||||
const double min = 21.0;
|
||||
double x;
|
||||
|
||||
x = 0;
|
||||
if (ft_clamp_d(x, min, max) != min)
|
||||
return (1);
|
||||
x = 21;
|
||||
if (ft_clamp_d(x, min, max) != min)
|
||||
return (1);
|
||||
x = 42;
|
||||
if (ft_clamp_d(x, min, max) != max)
|
||||
return (1);
|
||||
x = 84;
|
||||
if (ft_clamp_d(x, min, max) != max)
|
||||
return (1);
|
||||
x = 23;
|
||||
if (ft_clamp_d(x, min, max) != x)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
78
libft/tests/ft_math/tests_complex.c
Normal file
78
libft/tests/ft_math/tests_complex.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_complex.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:46:50 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 09:08:57 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
#include "ft_math_types.h"
|
||||
|
||||
int test_ft_complex_abs(void)
|
||||
{
|
||||
const t_complex x = {42, 0};
|
||||
const t_complex y = {0, 42};
|
||||
const t_complex z = {42, 42};
|
||||
double res;
|
||||
|
||||
res = ft_complex_abs(x);
|
||||
if (res < 41.99 || res > 42.01)
|
||||
return (1);
|
||||
res = ft_complex_abs(y);
|
||||
if (res < 41.99 || res > 42.01)
|
||||
return (2);
|
||||
res = ft_complex_abs(z);
|
||||
if (res < 59.39 || res > 59.41)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_complex_addl(void)
|
||||
{
|
||||
const t_complex x = {42, 0};
|
||||
const t_complex y = {0, 42};
|
||||
t_complex res;
|
||||
|
||||
res = ft_complex_addl(x, 42);
|
||||
if (res.real != 84 || res.imaginary != 42)
|
||||
return (1);
|
||||
res = ft_complex_addl(y, 42);
|
||||
if (res.real != 42 || res.imaginary != 84)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_complex_mull(void)
|
||||
{
|
||||
const t_complex x = {42, 0};
|
||||
const t_complex y = {0, 42};
|
||||
t_complex res;
|
||||
|
||||
res = ft_complex_mull(x, 2);
|
||||
if (res.real != 84 || res.imaginary != 0)
|
||||
return (1);
|
||||
res = ft_complex_mull(y, 2);
|
||||
if (res.real != 0 || res.imaginary != 84)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_complex_muld(void)
|
||||
{
|
||||
const t_complex x = {42, 0};
|
||||
const t_complex y = {0, 42};
|
||||
t_complex res;
|
||||
|
||||
res = ft_complex_muld(x, 2.5);
|
||||
if (res.real != 105 || res.imaginary != 0)
|
||||
return (1);
|
||||
res = ft_complex_muld(y, 2.5);
|
||||
if (res.real != 0 || res.imaginary != 105)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
134
libft/tests/ft_math/tests_intrange.c
Normal file
134
libft/tests/ft_math/tests_intrange.c
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_intrange.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:41:40 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/26 17:09:13 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_range_errors(void)
|
||||
{
|
||||
const int min = 9;
|
||||
const int max = 42;
|
||||
const int new_max = 21;
|
||||
int x;
|
||||
|
||||
x = -1;
|
||||
if (ft_range(x, min, max, new_max) != 0)
|
||||
return (1);
|
||||
x = min;
|
||||
if (ft_range(x, min + max, max, new_max) != 0)
|
||||
return (2);
|
||||
x = max + 1;
|
||||
if (ft_range(x, min, max, 0) != 0)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_range(void)
|
||||
{
|
||||
const int min = 9;
|
||||
const int max = 42;
|
||||
const int new_max = 21;
|
||||
int x;
|
||||
|
||||
x = -1;
|
||||
if (ft_range(x, min, max, new_max) != 0)
|
||||
return (1);
|
||||
x = min;
|
||||
if (ft_range(x, min, max, new_max) != 0)
|
||||
return (2);
|
||||
x = max + 1;
|
||||
if (ft_range(x, max, max, new_max) != 0)
|
||||
return (3);
|
||||
if (ft_range(x, min, max, new_max) != new_max)
|
||||
return (4);
|
||||
x = 42;
|
||||
if (ft_range(x, min, max, new_max) != new_max)
|
||||
return (5);
|
||||
x = 21;
|
||||
if (ft_range(x, min, max, new_max) != (int)(((double)(x - min) / \
|
||||
(max - min)) * new_max))
|
||||
return (6);
|
||||
return (test_ft_range_errors());
|
||||
}
|
||||
|
||||
int test_ft_range_f(void)
|
||||
{
|
||||
const float min = 9.0f;
|
||||
const float max = 42.0f;
|
||||
const float new_max = 21.0f;
|
||||
float x;
|
||||
|
||||
x = -1;
|
||||
if (ft_range_f(x, min, max, new_max) != 0)
|
||||
return (1);
|
||||
x = min;
|
||||
if (ft_range_f(x, min, max, new_max) != 0)
|
||||
return (2);
|
||||
x = max + 1;
|
||||
if (ft_range_f(x, max, max, new_max) != 0)
|
||||
return (3);
|
||||
if (ft_range_f(x, min, max, new_max) != new_max)
|
||||
return (4);
|
||||
x = 42;
|
||||
if (ft_range_f(x, min, max, new_max) != new_max)
|
||||
return (5);
|
||||
x = 21;
|
||||
if (ft_range_f(x, min, max, new_max) != \
|
||||
(float)(((double)(x - min) / (max - min)) * new_max))
|
||||
return (6);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_range_d_errors(void)
|
||||
{
|
||||
const double min = 9.0;
|
||||
const double max = 42.0;
|
||||
const double new_max = 21.0;
|
||||
double x;
|
||||
|
||||
x = -1;
|
||||
if (ft_range_d(x, min, max, new_max) != 0)
|
||||
return (1);
|
||||
x = min;
|
||||
if (ft_range_d(x, min + max, max, new_max) != 0)
|
||||
return (2);
|
||||
x = max + 1;
|
||||
if (ft_range_d(x, min, max, 0) != 0)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_range_d(void)
|
||||
{
|
||||
const double min = 9.0;
|
||||
const double max = 42.0;
|
||||
const double new_max = 21.0;
|
||||
double x;
|
||||
|
||||
x = -1;
|
||||
if (ft_range_d(x, min, max, new_max) != 0)
|
||||
return (1);
|
||||
x = min;
|
||||
if (ft_range_d(x, min, max, new_max) != 0)
|
||||
return (2);
|
||||
x = max + 1;
|
||||
if (ft_range_d(x, max, max, new_max) != 0)
|
||||
return (3);
|
||||
if (ft_range_d(x, min, max, new_max) != new_max)
|
||||
return (4);
|
||||
x = 42;
|
||||
if (ft_range_d(x, min, max, new_max) != new_max)
|
||||
return (5);
|
||||
x = 21;
|
||||
if (ft_range_d(x, min, max, new_max) != ((x - min) / (max - min)) * new_max)
|
||||
return (6);
|
||||
return (test_ft_range_d_errors());
|
||||
}
|
||||
74
libft/tests/ft_math/tests_log.c
Normal file
74
libft/tests/ft_math/tests_log.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_log.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:42:03 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 09:27:55 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_log(void)
|
||||
{
|
||||
int x;
|
||||
|
||||
x = 23;
|
||||
if (ft_log(x) != 1)
|
||||
return (1);
|
||||
x = 0;
|
||||
if (ft_log(x) != -1)
|
||||
return (2);
|
||||
x = 1;
|
||||
if (ft_log(x) != 0)
|
||||
return (3);
|
||||
x = 420;
|
||||
if (ft_log(x) != 2)
|
||||
return (4);
|
||||
x = -12;
|
||||
if (ft_log(x) != -1)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_llogof(void)
|
||||
{
|
||||
if (ft_llogof(0, 2) != -1)
|
||||
return (1);
|
||||
if (ft_llogof(1, 2) != 0)
|
||||
return (2);
|
||||
if (ft_llogof(2, 2) != 1)
|
||||
return (3);
|
||||
if (ft_llogof(8, 2) != 3)
|
||||
return (4);
|
||||
if (ft_llogof(23, 3) != 2)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_ullogof(void)
|
||||
{
|
||||
if (ft_ullogof(0, 2) != -1)
|
||||
return (1);
|
||||
if (ft_ullogof(1, 2) != 0)
|
||||
return (2);
|
||||
if (ft_ullogof(2, 2) != 1)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_logof(void)
|
||||
{
|
||||
if (ft_logof(0, 2) != -1)
|
||||
return (1);
|
||||
if (ft_logof(1, 2) != 0)
|
||||
return (2);
|
||||
if (ft_logof(2, 2) != 1)
|
||||
return (3);
|
||||
if (ft_logof(8, 2) != 3)
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
39
libft/tests/ft_math/tests_minmax.c
Normal file
39
libft/tests/ft_math/tests_minmax.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_minmax.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:49:30 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 00:54:36 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_min(void)
|
||||
{
|
||||
const int a = 1;
|
||||
const int b = 2;
|
||||
const int c = 3;
|
||||
|
||||
if (ft_min(a, b) != a)
|
||||
return (1);
|
||||
if (ft_min(b, c) != b)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_max(void)
|
||||
{
|
||||
const int a = 1;
|
||||
const int b = 2;
|
||||
const int c = 3;
|
||||
|
||||
if (ft_max(a, b) != b)
|
||||
return (1);
|
||||
if (ft_max(c, b) != c)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
33
libft/tests/ft_math/tests_pow.c
Normal file
33
libft/tests/ft_math/tests_pow.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pow.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:21:25 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 01:01:12 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_pow(void)
|
||||
{
|
||||
size_t x;
|
||||
size_t y;
|
||||
|
||||
x = 2;
|
||||
y = 3;
|
||||
if (ft_pow(x, y) != 8)
|
||||
return (1);
|
||||
y = 0;
|
||||
if (ft_pow(x, y) != 1)
|
||||
return (1);
|
||||
y = 1;
|
||||
if (ft_pow(x, y) != 2)
|
||||
return (1);
|
||||
if (ft_pow(0, y) != 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
32
libft/tests/ft_math/tests_round.c
Normal file
32
libft/tests/ft_math/tests_round.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_ft_round.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:24:56 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 23:25:46 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_round(void)
|
||||
{
|
||||
double x;
|
||||
|
||||
x = 42.42;
|
||||
if (ft_round(x) != 42)
|
||||
return (1);
|
||||
x = 42.52;
|
||||
if (ft_round(x) != 43)
|
||||
return (1);
|
||||
x = 42.499;
|
||||
if (ft_round(x) != 42)
|
||||
return (1);
|
||||
x = 42.5;
|
||||
if (ft_round(x) != 43)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
33
libft/tests/ft_math/tests_sqrt.c
Normal file
33
libft/tests/ft_math/tests_sqrt.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_sqrt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 23:49:48 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/24 09:34:56 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
int test_ft_sqrt(void)
|
||||
{
|
||||
double x;
|
||||
double result;
|
||||
|
||||
x = 4;
|
||||
result = ft_sqrt(x);
|
||||
if (result > 2.01 || result < 1.99)
|
||||
return (1);
|
||||
x = 2;
|
||||
result = ft_sqrt(x);
|
||||
if (result > 1.42 || result < 1.41)
|
||||
return (2);
|
||||
x = -1;
|
||||
result = ft_sqrt(x);
|
||||
if (result >= -0.99 || result <= -1.01)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
43
libft/tests/ft_optional/optional_tests.c
Normal file
43
libft/tests/ft_optional/optional_tests.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* optional_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/06 00:57:26 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 12:08:25 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/optional_test.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
void *add_4(void *val)
|
||||
{
|
||||
long long ptr;
|
||||
|
||||
ptr = (long long)val;
|
||||
ptr += 4;
|
||||
return ((void *)ptr);
|
||||
}
|
||||
|
||||
int tests_optional(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test test[] = {
|
||||
{"copy", test_optional_copy},
|
||||
{"new", test_optional_new},
|
||||
{"from_val", test_optional_from_val},
|
||||
{"dup", test_optional_dup},
|
||||
{"chain", test_optional_chain},
|
||||
{"map", test_optional_map},
|
||||
{"unwrap", test_optional_unwrap},
|
||||
{"destroy", test_optional_destroy},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
collect = 0;
|
||||
run_test(test, &collect);
|
||||
return (collect);
|
||||
}
|
||||
41
libft/tests/ft_optional/tests_optional_chain.c
Normal file
41
libft/tests/ft_optional/tests_optional_chain.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_chain.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:28:51 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:58:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include "tests/optional_test.h"
|
||||
#include "ft_defs.h"
|
||||
|
||||
int test_optional_chain(void)
|
||||
{
|
||||
t_optional opt;
|
||||
bool ret;
|
||||
const t_data_tr_i function_list[3] = {
|
||||
add_4,
|
||||
add_4,
|
||||
NULL
|
||||
};
|
||||
|
||||
opt.pres = OPT_SOME;
|
||||
opt.val = (void *)42;
|
||||
ret = ft_optional_chain(&opt, function_list);
|
||||
if (ret != true || opt.pres != OPT_SOME || opt.val != (void *)42 + 8)
|
||||
return (1);
|
||||
opt.pres = OPT_NONE;
|
||||
ret = ft_optional_chain(&opt, function_list);
|
||||
if (ret != false || opt.pres != OPT_NONE)
|
||||
return (1);
|
||||
ret = ft_optional_chain(&opt, NULL);
|
||||
if (ret != false || opt.pres != OPT_NONE)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_optional/tests_optional_copy.c
Normal file
34
libft/tests/ft_optional/tests_optional_copy.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_copy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:29:49 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 12:08:07 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int test_optional_copy(void)
|
||||
{
|
||||
int *ptr;
|
||||
t_optional opt_a;
|
||||
t_optional opt_b;
|
||||
|
||||
ptr = malloc(sizeof(int));
|
||||
*ptr = 42;
|
||||
opt_a.pres = OPT_SOME;
|
||||
opt_a.val = ptr;
|
||||
ft_optional_copy(&opt_b, &opt_a);
|
||||
if (opt_b.pres != OPT_SOME)
|
||||
return (1);
|
||||
if (*(int *)opt_b.val != 42)
|
||||
return (2);
|
||||
free(ptr);
|
||||
return (0);
|
||||
}
|
||||
35
libft/tests/ft_optional/tests_optional_destroy.c
Normal file
35
libft/tests/ft_optional/tests_optional_destroy.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_optional_destroy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:30:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 22:32:48 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
|
||||
int test_optional_destroy(void)
|
||||
{
|
||||
t_optional *opt_a;
|
||||
|
||||
opt_a = ft_optional_new();
|
||||
opt_a->val = (void *)42;
|
||||
opt_a->pres = OPT_SOME;
|
||||
if (ft_optional_destroy(opt_a) != false)
|
||||
return (1);
|
||||
if (opt_a->pres != OPT_SOME)
|
||||
return (2);
|
||||
if (opt_a->val != (void *)42)
|
||||
return (3);
|
||||
opt_a->pres = OPT_NONE;
|
||||
if (ft_optional_destroy(opt_a) != true)
|
||||
return (4);
|
||||
if (ft_optional_destroy(NULL) != false)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
33
libft/tests/ft_optional/tests_optional_dup.c
Normal file
33
libft/tests/ft_optional/tests_optional_dup.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_optional_dup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:30:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 22:32:45 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
|
||||
int test_optional_dup(void)
|
||||
{
|
||||
t_optional opt_a;
|
||||
t_optional *opt_b;
|
||||
|
||||
opt_a.pres = OPT_SOME;
|
||||
opt_a.val = (void *)42;
|
||||
opt_b = ft_optional_dup(&opt_a);
|
||||
if (!opt_b)
|
||||
return (1);
|
||||
if (opt_b->pres != OPT_SOME)
|
||||
return (2);
|
||||
if (opt_b->val != (void *)42)
|
||||
return (3);
|
||||
opt_b->pres = OPT_NONE;
|
||||
ft_optional_destroy(opt_b);
|
||||
return (0);
|
||||
}
|
||||
35
libft/tests/ft_optional/tests_optional_from_val.c
Normal file
35
libft/tests/ft_optional/tests_optional_from_val.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_optional_from_val.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:30:45 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 22:32:41 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int test_optional_from_val(void)
|
||||
{
|
||||
int *ptr;
|
||||
t_optional *opt;
|
||||
|
||||
ptr = malloc(sizeof(int));
|
||||
*ptr = 42;
|
||||
opt = ft_optional_from_val(ptr);
|
||||
if (!opt)
|
||||
return (1);
|
||||
if (opt->pres != OPT_SOME)
|
||||
return (2);
|
||||
if (opt->val != ptr)
|
||||
return (3);
|
||||
opt->pres = OPT_NONE;
|
||||
ft_optional_destroy(opt);
|
||||
free(ptr);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_optional/tests_optional_map.c
Normal file
34
libft/tests/ft_optional/tests_optional_map.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:31:24 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:59:14 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include "tests/optional_test.h"
|
||||
|
||||
int test_optional_map(void)
|
||||
{
|
||||
t_optional opt;
|
||||
t_optional ret;
|
||||
void *(*function_list[3])(void *);
|
||||
|
||||
function_list[0] = &add_4;
|
||||
function_list[1] = &add_4;
|
||||
function_list[2] = NULL;
|
||||
opt.pres = OPT_SOME;
|
||||
opt.val = (void *)42;
|
||||
ret = ft_optional_map(&opt, function_list);
|
||||
if (ret.pres != OPT_SOME)
|
||||
return (1);
|
||||
if (ret.val != (void *)42 + 8)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
29
libft/tests/ft_optional/tests_optional_new.c
Normal file
29
libft/tests/ft_optional/tests_optional_new.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_new.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:31:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/17 22:39:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
|
||||
int test_optional_new(void)
|
||||
{
|
||||
t_optional *opt;
|
||||
|
||||
opt = ft_optional_new();
|
||||
if (!opt)
|
||||
return (1);
|
||||
if (opt->pres != OPT_NONE)
|
||||
return (2);
|
||||
if (opt->val)
|
||||
return (3);
|
||||
ft_optional_destroy(opt);
|
||||
return (0);
|
||||
}
|
||||
37
libft/tests/ft_optional/tests_optional_unwrap.c
Normal file
37
libft/tests/ft_optional/tests_optional_unwrap.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_unwrap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:32:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/25 22:30:19 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int test_optional_unwrap(void)
|
||||
{
|
||||
t_optional opt;
|
||||
int *ptr;
|
||||
|
||||
opt.pres = OPT_SOME;
|
||||
ptr = malloc(sizeof(int));
|
||||
*ptr = 42;
|
||||
opt.val = ptr;
|
||||
if (ft_optional_unwrap(opt) != ptr)
|
||||
return (1);
|
||||
free(ptr);
|
||||
opt.pres = OPT_NONE;
|
||||
opt.val = (void *)0xDEADBEEF;
|
||||
if (ft_optional_unwrap(opt) != NULL)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_pair/pair_tests.c
Normal file
34
libft/tests/ft_pair/pair_tests.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pair_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 15:53:09 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/06 17:15:20 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/pair_tests.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
int tests_pair(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test test[] = {
|
||||
{"test_pair_set", test_pair_set},
|
||||
{"test_pair_new", test_pair_new},
|
||||
{"test_pair_second", test_pair_second},
|
||||
{"test_pair_first", test_pair_first},
|
||||
{"test_pair_cmp", test_pair_cmp},
|
||||
{"test_pair_cmp_first", test_pair_cmp_first},
|
||||
{"test_pair_cmp_second", test_pair_cmp_second},
|
||||
{"tests_pair_destroy", tests_pair_destroy},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
collect = 0;
|
||||
run_test(test, &collect);
|
||||
return (collect);
|
||||
}
|
||||
74
libft/tests/ft_pair/tests_pair_cmp.c
Normal file
74
libft/tests/ft_pair/tests_pair_cmp.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pair_cmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 16:20:58 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/08/21 21:43:29 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_pair.h"
|
||||
#include "ft_pair_types.h"
|
||||
#include "tests/pair_tests.h"
|
||||
#include "tests/tests_lambda_functions.h"
|
||||
|
||||
static int test_ptr(void)
|
||||
{
|
||||
t_pair pair_a;
|
||||
t_pair pair_b;
|
||||
void *a;
|
||||
void *b;
|
||||
void *c;
|
||||
|
||||
a = (void *)0xDEADBEEF;
|
||||
b = (void *)0xDEADDEAD;
|
||||
c = (void *)0xDEADCAFE;
|
||||
ft_pair_set(&pair_a, a, b);
|
||||
ft_pair_set(&pair_b, c, a);
|
||||
if (ft_pair_cmp(&pair_a, &pair_b, NULL) == 0)
|
||||
return (1);
|
||||
if (ft_pair_cmp(&pair_a, &pair_a, NULL) != 0)
|
||||
return (2);
|
||||
if (ft_pair_cmp(&pair_b, &pair_a, NULL) == 0)
|
||||
return (3);
|
||||
if (ft_pair_cmp(NULL, &pair_a, NULL) == 0 || ft_pair_cmp(&pair_a, NULL,
|
||||
NULL) == 0)
|
||||
return (4);
|
||||
if (ft_pair_cmp(NULL, NULL, NULL) != 0)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test_cmp(void)
|
||||
{
|
||||
t_pair pair_a;
|
||||
t_pair pair_b;
|
||||
long a;
|
||||
long b;
|
||||
long c;
|
||||
|
||||
a = 21;
|
||||
b = 42;
|
||||
c = 420;
|
||||
ft_pair_set(&pair_a, (void *)a, (void *)b);
|
||||
ft_pair_set(&pair_b, (void *)c, (void *)a);
|
||||
if (ft_pair_cmp(&pair_a, &pair_b, &cmp_int) == 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_pair_cmp(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = test_ptr();
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = test_cmp();
|
||||
if (ret != 0)
|
||||
return (ret + 10);
|
||||
return (0);
|
||||
}
|
||||
74
libft/tests/ft_pair/tests_pair_cmp_first.c
Normal file
74
libft/tests/ft_pair/tests_pair_cmp_first.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pair_cmp_first.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 16:20:45 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/08/21 21:48:51 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_defs.h"
|
||||
#include "ft_pair.h"
|
||||
#include "ft_pair_types.h"
|
||||
#include "ft_string.h"
|
||||
#include "tests/pair_tests.h"
|
||||
|
||||
static int test_ptr(void)
|
||||
{
|
||||
t_pair pair;
|
||||
t_pair pair_b;
|
||||
void *a;
|
||||
void *b;
|
||||
void *c;
|
||||
|
||||
a = (void *)0xDEADBEEF;
|
||||
b = (void *)0xDEADCAFE;
|
||||
c = (void *)0xDEADDEAD;
|
||||
ft_pair_set(&pair, b, b);
|
||||
pair_b.first = c;
|
||||
if (ft_pair_cmp_first(&pair, &pair_b, NULL) >= 0)
|
||||
return (1);
|
||||
pair_b.first = b;
|
||||
if (ft_pair_cmp_first(&pair, &pair_b, NULL) != 0)
|
||||
return (2);
|
||||
pair_b.first = a;
|
||||
if (ft_pair_cmp_first(&pair, &pair_b, NULL) <= 0)
|
||||
return (3);
|
||||
if (ft_pair_cmp_first(&pair, NULL, NULL) == 0 || ft_pair_cmp_first(NULL,
|
||||
&pair, NULL) == 0)
|
||||
return (4);
|
||||
if (ft_pair_cmp_first(NULL, NULL, NULL) != 0)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test_cmp(void)
|
||||
{
|
||||
t_pair pair_a;
|
||||
t_pair pair_b;
|
||||
const char *a = "a";
|
||||
const char *b = "b";
|
||||
const char *c = "c";
|
||||
|
||||
ft_pair_set(&pair_a, (void *)a, (void *)b);
|
||||
ft_pair_set(&pair_b, (void *)c, (void *)a);
|
||||
if (ft_pair_cmp_first(&pair_a, &pair_b, (t_data_cmp) & ft_strcmp) == 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_pair_cmp_first(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = test_ptr();
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = test_cmp();
|
||||
if (ret != 0)
|
||||
return (ret + 10);
|
||||
return (0);
|
||||
}
|
||||
73
libft/tests/ft_pair/tests_pair_cmp_second.c
Normal file
73
libft/tests/ft_pair/tests_pair_cmp_second.c
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pair_cmp_second.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 16:19:11 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/08/21 21:48:39 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_pair.h"
|
||||
#include "ft_pair_types.h"
|
||||
#include "ft_string.h"
|
||||
#include "tests/pair_tests.h"
|
||||
|
||||
static int test_ptr(void)
|
||||
{
|
||||
t_pair pair;
|
||||
t_pair pair_b;
|
||||
void *a;
|
||||
void *b;
|
||||
void *c;
|
||||
|
||||
a = (void *)0xDEADBEEF;
|
||||
b = (void *)0xDEADCAFE;
|
||||
c = (void *)0xDEADDEAD;
|
||||
pair_b.second = c;
|
||||
ft_pair_set(&pair, b, b);
|
||||
if (ft_pair_cmp_second(&pair, &pair_b, NULL) >= 0)
|
||||
return (1);
|
||||
pair_b.second = b;
|
||||
if (ft_pair_cmp_second(&pair, &pair_b, NULL) != 0)
|
||||
return (2);
|
||||
pair_b.second = a;
|
||||
if (ft_pair_cmp_second(&pair, &pair_b, NULL) <= 0)
|
||||
return (3);
|
||||
if (ft_pair_cmp_second(&pair, NULL, NULL) == 0 || ft_pair_cmp_second(NULL,
|
||||
&pair, NULL) == 0)
|
||||
return (4);
|
||||
if (ft_pair_cmp_second(NULL, NULL, NULL) != 0)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test_cmp(void)
|
||||
{
|
||||
t_pair pair_a;
|
||||
t_pair pair_b;
|
||||
const char *a = "a";
|
||||
const char *b = "b";
|
||||
const char *c = "c";
|
||||
|
||||
ft_pair_set(&pair_a, (void *)a, (void *)b);
|
||||
ft_pair_set(&pair_b, (void *)c, (void *)a);
|
||||
if (ft_pair_cmp_second(&pair_a, &pair_b, (t_data_cmp) & ft_strcmp) == 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_pair_cmp_second(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = test_ptr();
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = test_cmp();
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_pair/tests_pair_destroy.c
Normal file
34
libft/tests/ft_pair/tests_pair_destroy.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pair_destroy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 17:09:25 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/06 17:16:28 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "tests/pair_tests.h"
|
||||
#include "ft_pair_types.h"
|
||||
#include "ft_pair.h"
|
||||
|
||||
int tests_pair_destroy(void)
|
||||
{
|
||||
t_pair *pair;
|
||||
|
||||
pair = ft_pair_new("key", "value");
|
||||
ft_pair_destroy(&pair, NULL, NULL);
|
||||
if (pair != NULL)
|
||||
return (1);
|
||||
pair = ft_pair_new(ft_strdup("key"), ft_strdup("value"));
|
||||
ft_pair_destroy(&pair, &free, &free);
|
||||
if (pair != NULL)
|
||||
return (2);
|
||||
ft_pair_destroy(NULL, NULL, NULL);
|
||||
pair = NULL;
|
||||
ft_pair_destroy(&pair, NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
31
libft/tests/ft_pair/tests_pair_get_first.c
Normal file
31
libft/tests/ft_pair/tests_pair_get_first.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pair_get_first.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 16:17:14 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/06 17:04:32 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_pair.h"
|
||||
#include "ft_pair_types.h"
|
||||
#include "tests/pair_tests.h"
|
||||
|
||||
int test_pair_first(void)
|
||||
{
|
||||
t_pair pair;
|
||||
void *a;
|
||||
void *b;
|
||||
|
||||
a = (void *)0xDEADBEEF;
|
||||
b = (void *)0xDEADDEAD;
|
||||
ft_pair_set(&pair, a, b);
|
||||
if (ft_pair_first(&pair) != a)
|
||||
return (1);
|
||||
if (ft_pair_first(NULL) != NULL)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
31
libft/tests/ft_pair/tests_pair_get_second.c
Normal file
31
libft/tests/ft_pair/tests_pair_get_second.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pair_get_second.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 16:15:50 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/06 17:04:40 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_pair.h"
|
||||
#include "ft_pair_types.h"
|
||||
#include "tests/pair_tests.h"
|
||||
|
||||
int test_pair_second(void)
|
||||
{
|
||||
t_pair pair;
|
||||
void *a;
|
||||
void *b;
|
||||
|
||||
a = (void *)0xDEADBEEF;
|
||||
b = (void *)0xDEADDEAD;
|
||||
ft_pair_set(&pair, a, b);
|
||||
if (ft_pair_second(&pair) != b)
|
||||
return (1);
|
||||
if (ft_pair_second(NULL) != NULL)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
35
libft/tests/ft_pair/tests_pair_new.c
Normal file
35
libft/tests/ft_pair/tests_pair_new.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pair_new.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 16:14:03 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/06 17:25:03 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_pair.h"
|
||||
#include "ft_pair_types.h"
|
||||
#include "tests/pair_tests.h"
|
||||
|
||||
int test_pair_new(void)
|
||||
{
|
||||
t_pair *pair;
|
||||
void *a;
|
||||
void *b;
|
||||
|
||||
a = (void *)0xDEADBEEF;
|
||||
b = (void *)0xDEADDEAD;
|
||||
pair = ft_pair_new(NULL, NULL);
|
||||
if (!pair)
|
||||
return (1);
|
||||
if (pair->first || pair->second)
|
||||
return (2);
|
||||
ft_pair_set(pair, a, b);
|
||||
if (pair->first != a || pair->second != b)
|
||||
return (3);
|
||||
ft_pair_destroy(&pair, NULL, NULL);
|
||||
return (0);
|
||||
}
|
||||
35
libft/tests/ft_pair/tests_pair_set.c
Normal file
35
libft/tests/ft_pair/tests_pair_set.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_pair_set.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 16:09:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/06 16:46:25 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_pair.h"
|
||||
#include "ft_pair_types.h"
|
||||
#include "tests/pair_tests.h"
|
||||
|
||||
int test_pair_set(void)
|
||||
{
|
||||
t_pair pair;
|
||||
void *a;
|
||||
void *b;
|
||||
void *c;
|
||||
|
||||
a = (void *)0xDEADBEEF;
|
||||
b = (void *)0xDEADDEAD;
|
||||
c = (void *)0xDEADCAFE;
|
||||
ft_pair_set(&pair, a, b);
|
||||
if (pair.first != a || pair.second != b)
|
||||
return (1);
|
||||
ft_pair_set(&pair, c, a);
|
||||
if (pair.first != c || pair.second != a)
|
||||
return (1);
|
||||
ft_pair_set(NULL, a, b);
|
||||
return (0);
|
||||
}
|
||||
31
libft/tests/ft_string/ft_char/ft_char_tests.c
Normal file
31
libft/tests/ft_string/ft_char/ft_char_tests.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_char_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 14:31:03 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:37:50 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/char_tests.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
int char_tests(void)
|
||||
{
|
||||
int i;
|
||||
const t_test tests[] = {
|
||||
{"isalnum", test_ft_isalnum}, {"isalpha", test_ft_isalpha},
|
||||
{"isascii", test_ft_isascii}, {"isdigit", test_ft_isdigit},
|
||||
{"isprint", test_ft_isprint}, {"tolower", test_ft_tolower},
|
||||
{"toupper", test_ft_toupper}, {"isalnum", test_ft_isalnum},
|
||||
{"putchar", test_ft_putchar}, {"ishexdigit", test_ft_ishexdigit},
|
||||
{"isoctdigit", test_ft_isoctdigit}, {"isspace", test_ft_isspace},
|
||||
{NULL, NULL}};
|
||||
|
||||
i = 0;
|
||||
run_test(tests, &i);
|
||||
return (i);
|
||||
}
|
||||
28
libft/tests/ft_string/ft_char/tests_isalnum.c
Normal file
28
libft/tests/ft_string/ft_char/tests_isalnum.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:55:54 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:11:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isalnum(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isalnum(i) != ((i >= '0' && i <= '9') || (i >= 'a' && i <= 'z')
|
||||
|| (i >= 'A' && i <= 'Z')))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft/tests/ft_string/ft_char/tests_isalpha.c
Normal file
27
libft/tests/ft_string/ft_char/tests_isalpha.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:56:07 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 15:56:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isalpha(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isalpha(i) != ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z')))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft/tests/ft_string/ft_char/tests_isascii.c
Normal file
27
libft/tests/ft_string/ft_char/tests_isascii.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:56:46 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:30:15 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isascii(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isascii(i) != (i >= 0 && i <= 127))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft/tests/ft_string/ft_char/tests_isdigit.c
Normal file
27
libft/tests/ft_string/ft_char/tests_isdigit.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:57:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 15:57:55 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isdigit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isdigit(i) != (i >= '0' && i <= '9'))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
35
libft/tests/ft_string/ft_char/tests_ishexdigit.c
Normal file
35
libft/tests/ft_string/ft_char/tests_ishexdigit.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_ishexdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:25:47 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:26:01 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_ishexdigit(int c)
|
||||
{
|
||||
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')
|
||||
|| (c >= 'A' && c <= 'F'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_ishexdigit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_ishexdigit(i) != local_ishexdigit(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_string/ft_char/tests_isoctdigit.c
Normal file
34
libft/tests/ft_string/ft_char/tests_isoctdigit.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isoctdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:26:13 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:26:23 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_isoctdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '7')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_isoctdigit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isoctdigit(i) != local_isoctdigit(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft/tests/ft_string/ft_char/tests_isprint.c
Normal file
27
libft/tests/ft_string/ft_char/tests_isprint.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:57:59 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 15:58:04 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isprint(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isprint(i) != (i >= 32 && i <= 126))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
35
libft/tests/ft_string/ft_char/tests_isspace.c
Normal file
35
libft/tests/ft_string/ft_char/tests_isspace.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_char_isspace.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:32:37 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 21:25:51 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_isspace(int c)
|
||||
{
|
||||
if (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t'
|
||||
|| c == '\v')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_isspace(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isspace(i) != local_isspace(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
46
libft/tests/ft_string/ft_char/tests_puchar.c
Normal file
46
libft/tests/ft_string/ft_char/tests_puchar.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_puchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:01:41 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:18:25 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
#include "tests/tests.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int test_ft_putchar(void)
|
||||
{
|
||||
const char *file;
|
||||
char buf[256];
|
||||
char c;
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
file = "ft_putchar";
|
||||
c = 0;
|
||||
fd = open_test_file((char **)&file);
|
||||
if (fd < 0)
|
||||
return (1);
|
||||
while ((unsigned char)c < 255)
|
||||
ft_putchar_fd(c++, fd);
|
||||
close(fd);
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return (2);
|
||||
ret = read(fd, buf, 256);
|
||||
if (ret != 255)
|
||||
return (3);
|
||||
buf[255] = 0;
|
||||
while (ret--)
|
||||
if (buf[ret] != --c)
|
||||
return (4);
|
||||
return (destroy_test_file(fd, (char *)file), free((char *)file), 0);
|
||||
}
|
||||
34
libft/tests/ft_string/ft_char/tests_tolower.c
Normal file
34
libft/tests/ft_string/ft_char/tests_tolower.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:59:59 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:00:44 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c + 32);
|
||||
return (c);
|
||||
}
|
||||
|
||||
int test_ft_tolower(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_tolower(i) != local_tolower(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_string/ft_char/tests_toupper.c
Normal file
34
libft/tests/ft_string/ft_char/tests_toupper.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:01:14 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:18:41 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
return (c);
|
||||
}
|
||||
|
||||
int test_ft_toupper(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_toupper(i) != local_toupper(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
32
libft/tests/ft_string/ft_mem/mem_tests.c
Normal file
32
libft/tests/ft_string/ft_mem/mem_tests.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/30 13:39:27 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 20:54:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/tests.h"
|
||||
#include "tests/str__mem_tests.h"
|
||||
|
||||
int mem_tests(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test tests[] = {
|
||||
{"apply_2d", test_apply_2d}, {"free_2d", test_free_2d},
|
||||
{"len_2d", test_len_2d}, {"fd_to_buff", test_fd_to_buff},
|
||||
{"bzero", test_bzero}, {"calloc", test_calloc}, {"realloc", test_realloc},
|
||||
{"free", test_free}, {"memchr", test_memchr}, {"memcmp", test_memcmp},
|
||||
{"memcpy", test_memcpy}, {"memmap", test_memmap}, {"memmove", test_memmove},
|
||||
{"memset", test_memset}, {"swap", test_swap}, {"qsort", test_qsort},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
collect = 0;
|
||||
run_test(tests, &collect);
|
||||
return (collect);
|
||||
}
|
||||
41
libft/tests/ft_string/ft_mem/tests_apply_2d.c
Normal file
41
libft/tests/ft_string/ft_mem/tests_apply_2d.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_apply_2d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 16:05:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:59:40 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
static void to_a(void *ptr)
|
||||
{
|
||||
char *sptr;
|
||||
|
||||
sptr = (char *)ptr;
|
||||
while (*sptr)
|
||||
{
|
||||
*sptr = 'a';
|
||||
sptr++;
|
||||
}
|
||||
}
|
||||
|
||||
int test_apply_2d(void)
|
||||
{
|
||||
char *arr2d[4];
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < 3)
|
||||
arr2d[i++] = ft_strdup("Hello World");
|
||||
arr2d[i] = NULL;
|
||||
ft_apply_2d((void **)arr2d, to_a);
|
||||
if (ft_strcmp(arr2d[0], "aaaaaaaaaaa") != 0 || ft_strcmp(arr2d[1],
|
||||
"aaaaaaaaaaa") != 0 || ft_strcmp(arr2d[2], "aaaaaaaaaaa") != 0)
|
||||
return (1);
|
||||
return (ft_apply_2d((void **)arr2d, free), 0);
|
||||
}
|
||||
25
libft/tests/ft_string/ft_mem/tests_bzero.c
Normal file
25
libft/tests/ft_string/ft_mem/tests_bzero.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:24:17 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 14:37:09 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_bzero(void)
|
||||
{
|
||||
char str[10];
|
||||
const char str2[10] = {0};
|
||||
|
||||
ft_strlcpy(str, "123456789", 10);
|
||||
ft_bzero(str, 10);
|
||||
if (ft_memcmp(str, str2, 10) != 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
33
libft/tests/ft_string/ft_mem/tests_calloc.c
Normal file
33
libft/tests/ft_string/ft_mem/tests_calloc.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:23:35 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/25 21:40:19 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// str[x] = 'a' is to test that we can write in the memory we asked for
|
||||
int test_calloc(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = ft_calloc(10, sizeof(char));
|
||||
str[9] = 'a';
|
||||
free(str);
|
||||
str = ft_calloc(10, sizeof(char *));
|
||||
str[9 * sizeof(char *)] = 'a';
|
||||
free(str);
|
||||
str = ft_calloc(0, sizeof(char));
|
||||
free(str);
|
||||
str = ft_calloc(SIZE_MAX, SIZE_MAX);
|
||||
if (str)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
71
libft/tests/ft_string/ft_mem/tests_fd_to_buff.c
Normal file
71
libft/tests/ft_string/ft_mem/tests_fd_to_buff.c
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_fd_to_buff.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 16:15:20 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/26 19:34:37 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
static int base_case(void)
|
||||
{
|
||||
char buff[100];
|
||||
char *ret;
|
||||
int fd;
|
||||
|
||||
ft_bzero(buff, 100);
|
||||
ft_strlcat(buff, "Hello World\n\n\n\n\tv\vjkldqskjfsldfjsmldfkj\n", 100);
|
||||
fd = open(TESTS_FPREFIX "test_fd_to_buff.txt", O_RDWR | O_CREAT, 0644);
|
||||
if (fd < 0)
|
||||
return (1);
|
||||
write(fd, buff, ft_strlen(buff));
|
||||
close(fd);
|
||||
fd = open(TESTS_FPREFIX "test_fd_to_buff.txt", O_RDONLY | O_CREAT);
|
||||
if (fd < 0)
|
||||
return (2);
|
||||
ret = ft_fd_to_buff(fd);
|
||||
if (ft_strcmp(ret, buff) != 0)
|
||||
return (3);
|
||||
destroy_test_file(fd, TESTS_FPREFIX "test_fd_to_buff.txt");
|
||||
return (free(ret), 0);
|
||||
}
|
||||
|
||||
static int error_case(void)
|
||||
{
|
||||
char *ret;
|
||||
int bad_fd;
|
||||
|
||||
bad_fd = -1;
|
||||
ret = ft_fd_to_buff(bad_fd);
|
||||
if (ret)
|
||||
return (1);
|
||||
bad_fd = open(TESTS_FPREFIX "test_fd_to_buff.txt", O_CREAT, 0004);
|
||||
if (bad_fd < 0)
|
||||
return (2);
|
||||
close(bad_fd);
|
||||
bad_fd = open(TESTS_FPREFIX "test_fd_to_buff.txt", O_RDONLY);
|
||||
ret = ft_fd_to_buff(bad_fd);
|
||||
if (ret)
|
||||
return (3);
|
||||
destroy_test_file(bad_fd, TESTS_FPREFIX "test_fd_to_buff.txt");
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_fd_to_buff(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = base_case();
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = error_case();
|
||||
if (ret != 0)
|
||||
return (ret + 10);
|
||||
return (0);
|
||||
}
|
||||
26
libft/tests/ft_string/ft_mem/tests_free.c
Normal file
26
libft/tests/ft_string/ft_mem/tests_free.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_free.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:22:59 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/08/21 21:49:05 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_free(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = ft_calloc(10, sizeof(char));
|
||||
ft_free((void **)&str);
|
||||
if (str)
|
||||
return (1);
|
||||
ft_free((void **)&str);
|
||||
ft_free((void **) NULL);
|
||||
return (0);
|
||||
}
|
||||
24
libft/tests/ft_string/ft_mem/tests_free_2d.c
Normal file
24
libft/tests/ft_string/ft_mem/tests_free_2d.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_free_2d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 23:42:53 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/28 23:55:41 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
// we assume that free_2d is working,
|
||||
// checking if memory is freed properly is not possible in this context
|
||||
int test_free_2d(void)
|
||||
{
|
||||
char **tab;
|
||||
|
||||
tab = ft_split("Hello World", ' ');
|
||||
ft_free_2d((void **)tab);
|
||||
return (0);
|
||||
}
|
||||
26
libft/tests/ft_string/ft_mem/tests_len_2d.c
Normal file
26
libft/tests/ft_string/ft_mem/tests_len_2d.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_len_2d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 00:11:07 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/29 00:15:46 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_len_2d(void)
|
||||
{
|
||||
char *arr2d[4];
|
||||
|
||||
arr2d[0] = "Hello";
|
||||
arr2d[1] = "World";
|
||||
arr2d[2] = "!";
|
||||
arr2d[3] = NULL;
|
||||
if (ft_len_2d((const void *const *)arr2d) != 3)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue