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
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