added bgoulard lib + made lib sources in their own directory in build/ for readability
This commit is contained in:
parent
83cc8419a0
commit
0a390934d6
457 changed files with 21807 additions and 61 deletions
52
libft_personal/tests/ft_list/dl_tests/dl_list_tests.c
Normal file
52
libft_personal/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_personal/tests/ft_list/dl_tests/dl_tests_utils.c
Normal file
26
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_add.c
Normal file
73
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_apply.c
Normal file
72
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_clear.c
Normal file
68
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_copy.c
Normal file
65
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_create.c
Normal file
34
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_delete.c
Normal file
110
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_find.c
Normal file
45
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_get.c
Normal file
60
libft_personal/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);
|
||||
}
|
||||
|
|
@ -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_personal/tests/ft_list/dl_tests/tests_dlist_map.c
Normal file
46
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_new.c
Normal file
26
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_push.c
Normal file
115
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_rev.c
Normal file
41
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_sizers.c
Normal file
59
libft_personal/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_personal/tests/ft_list/dl_tests/tests_dlist_subrange.c
Normal file
44
libft_personal/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_personal/tests/ft_list/ll_tests/ll_list_tests.c
Normal file
43
libft_personal/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_personal/tests/ft_list/ll_tests/ll_tests_utils.c
Normal file
26
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_add.c
Normal file
65
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_apply.c
Normal file
92
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_clear.c
Normal file
30
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_copy.c
Normal file
62
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_create.c
Normal file
34
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_deletors.c
Normal file
81
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_find.c
Normal file
46
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_get.c
Normal file
54
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_iterators.c
Normal file
59
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_map.c
Normal file
43
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_new.c
Normal file
26
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_push.c
Normal file
134
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_rev.c
Normal file
39
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_sizers.c
Normal file
59
libft_personal/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_personal/tests/ft_list/ll_tests/tests_list_subrange.c
Normal file
53
libft_personal/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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue