added bgoulard lib + made lib sources in their own directory in build/ for readability

This commit is contained in:
B.Goulard 2024-11-01 00:00:14 +01:00
parent 83cc8419a0
commit 0a390934d6
457 changed files with 21807 additions and 61 deletions

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}

View 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);
}