removing the libft of rparodi
This commit is contained in:
parent
0391323626
commit
be6038dcc8
523 changed files with 724 additions and 3336 deletions
43
libft/tests/ft_optional/optional_tests.c
Normal file
43
libft/tests/ft_optional/optional_tests.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* optional_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/06 00:57:26 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 12:08:25 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/optional_test.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
void *add_4(void *val)
|
||||
{
|
||||
long long ptr;
|
||||
|
||||
ptr = (long long)val;
|
||||
ptr += 4;
|
||||
return ((void *)ptr);
|
||||
}
|
||||
|
||||
int tests_optional(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test test[] = {
|
||||
{"copy", test_optional_copy},
|
||||
{"new", test_optional_new},
|
||||
{"from_val", test_optional_from_val},
|
||||
{"dup", test_optional_dup},
|
||||
{"chain", test_optional_chain},
|
||||
{"map", test_optional_map},
|
||||
{"unwrap", test_optional_unwrap},
|
||||
{"destroy", test_optional_destroy},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
collect = 0;
|
||||
run_test(test, &collect);
|
||||
return (collect);
|
||||
}
|
||||
41
libft/tests/ft_optional/tests_optional_chain.c
Normal file
41
libft/tests/ft_optional/tests_optional_chain.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_chain.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:28:51 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:58:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include "tests/optional_test.h"
|
||||
#include "ft_defs.h"
|
||||
|
||||
int test_optional_chain(void)
|
||||
{
|
||||
t_optional opt;
|
||||
bool ret;
|
||||
const t_data_tr_i function_list[3] = {
|
||||
add_4,
|
||||
add_4,
|
||||
NULL
|
||||
};
|
||||
|
||||
opt.pres = OPT_SOME;
|
||||
opt.val = (void *)42;
|
||||
ret = ft_optional_chain(&opt, function_list);
|
||||
if (ret != true || opt.pres != OPT_SOME || opt.val != (void *)42 + 8)
|
||||
return (1);
|
||||
opt.pres = OPT_NONE;
|
||||
ret = ft_optional_chain(&opt, function_list);
|
||||
if (ret != false || opt.pres != OPT_NONE)
|
||||
return (1);
|
||||
ret = ft_optional_chain(&opt, NULL);
|
||||
if (ret != false || opt.pres != OPT_NONE)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_optional/tests_optional_copy.c
Normal file
34
libft/tests/ft_optional/tests_optional_copy.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_copy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:29:49 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 12:08:07 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int test_optional_copy(void)
|
||||
{
|
||||
int *ptr;
|
||||
t_optional opt_a;
|
||||
t_optional opt_b;
|
||||
|
||||
ptr = malloc(sizeof(int));
|
||||
*ptr = 42;
|
||||
opt_a.pres = OPT_SOME;
|
||||
opt_a.val = ptr;
|
||||
ft_optional_copy(&opt_b, &opt_a);
|
||||
if (opt_b.pres != OPT_SOME)
|
||||
return (1);
|
||||
if (*(int *)opt_b.val != 42)
|
||||
return (2);
|
||||
free(ptr);
|
||||
return (0);
|
||||
}
|
||||
35
libft/tests/ft_optional/tests_optional_destroy.c
Normal file
35
libft/tests/ft_optional/tests_optional_destroy.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_optional_destroy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:30:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 22:32:48 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
|
||||
int test_optional_destroy(void)
|
||||
{
|
||||
t_optional *opt_a;
|
||||
|
||||
opt_a = ft_optional_new();
|
||||
opt_a->val = (void *)42;
|
||||
opt_a->pres = OPT_SOME;
|
||||
if (ft_optional_destroy(opt_a) != false)
|
||||
return (1);
|
||||
if (opt_a->pres != OPT_SOME)
|
||||
return (2);
|
||||
if (opt_a->val != (void *)42)
|
||||
return (3);
|
||||
opt_a->pres = OPT_NONE;
|
||||
if (ft_optional_destroy(opt_a) != true)
|
||||
return (4);
|
||||
if (ft_optional_destroy(NULL) != false)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
33
libft/tests/ft_optional/tests_optional_dup.c
Normal file
33
libft/tests/ft_optional/tests_optional_dup.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_optional_dup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:30:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 22:32:45 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
|
||||
int test_optional_dup(void)
|
||||
{
|
||||
t_optional opt_a;
|
||||
t_optional *opt_b;
|
||||
|
||||
opt_a.pres = OPT_SOME;
|
||||
opt_a.val = (void *)42;
|
||||
opt_b = ft_optional_dup(&opt_a);
|
||||
if (!opt_b)
|
||||
return (1);
|
||||
if (opt_b->pres != OPT_SOME)
|
||||
return (2);
|
||||
if (opt_b->val != (void *)42)
|
||||
return (3);
|
||||
opt_b->pres = OPT_NONE;
|
||||
ft_optional_destroy(opt_b);
|
||||
return (0);
|
||||
}
|
||||
35
libft/tests/ft_optional/tests_optional_from_val.c
Normal file
35
libft/tests/ft_optional/tests_optional_from_val.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_optional_from_val.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:30:45 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 22:32:41 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int test_optional_from_val(void)
|
||||
{
|
||||
int *ptr;
|
||||
t_optional *opt;
|
||||
|
||||
ptr = malloc(sizeof(int));
|
||||
*ptr = 42;
|
||||
opt = ft_optional_from_val(ptr);
|
||||
if (!opt)
|
||||
return (1);
|
||||
if (opt->pres != OPT_SOME)
|
||||
return (2);
|
||||
if (opt->val != ptr)
|
||||
return (3);
|
||||
opt->pres = OPT_NONE;
|
||||
ft_optional_destroy(opt);
|
||||
free(ptr);
|
||||
return (0);
|
||||
}
|
||||
34
libft/tests/ft_optional/tests_optional_map.c
Normal file
34
libft/tests/ft_optional/tests_optional_map.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:31:24 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:59:14 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include "tests/optional_test.h"
|
||||
|
||||
int test_optional_map(void)
|
||||
{
|
||||
t_optional opt;
|
||||
t_optional ret;
|
||||
void *(*function_list[3])(void *);
|
||||
|
||||
function_list[0] = &add_4;
|
||||
function_list[1] = &add_4;
|
||||
function_list[2] = NULL;
|
||||
opt.pres = OPT_SOME;
|
||||
opt.val = (void *)42;
|
||||
ret = ft_optional_map(&opt, function_list);
|
||||
if (ret.pres != OPT_SOME)
|
||||
return (1);
|
||||
if (ret.val != (void *)42 + 8)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
29
libft/tests/ft_optional/tests_optional_new.c
Normal file
29
libft/tests/ft_optional/tests_optional_new.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_new.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:31:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/17 22:39:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
|
||||
int test_optional_new(void)
|
||||
{
|
||||
t_optional *opt;
|
||||
|
||||
opt = ft_optional_new();
|
||||
if (!opt)
|
||||
return (1);
|
||||
if (opt->pres != OPT_NONE)
|
||||
return (2);
|
||||
if (opt->val)
|
||||
return (3);
|
||||
ft_optional_destroy(opt);
|
||||
return (0);
|
||||
}
|
||||
37
libft/tests/ft_optional/tests_optional_unwrap.c
Normal file
37
libft/tests/ft_optional/tests_optional_unwrap.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_optional_unwrap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 22:32:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/25 22:30:19 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_optional.h"
|
||||
#include "ft_optional_types.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int test_optional_unwrap(void)
|
||||
{
|
||||
t_optional opt;
|
||||
int *ptr;
|
||||
|
||||
opt.pres = OPT_SOME;
|
||||
ptr = malloc(sizeof(int));
|
||||
*ptr = 42;
|
||||
opt.val = ptr;
|
||||
if (ft_optional_unwrap(opt) != ptr)
|
||||
return (1);
|
||||
free(ptr);
|
||||
opt.pres = OPT_NONE;
|
||||
opt.val = (void *)0xDEADBEEF;
|
||||
if (ft_optional_unwrap(opt) != NULL)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue