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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue