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,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* math_tests.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:16:35 by bgoulard #+# #+# */
/* Updated: 2024/06/26 20:50:59 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests/tests.h"
#include "tests/math_tests.h"
int tests_math(void)
{
int i;
const t_test tests[] = {
{"abs", test_ft_abs}, {"clamp", test_ft_clamp},
{"complex_abs", test_ft_complex_abs},
{"complex_addl", test_ft_complex_addl},
{"complex_mull", test_ft_complex_mull},
{"complex_muld", test_ft_complex_muld},
{"range", test_ft_range}, {"range_f", test_ft_range_f},
{"range_d", test_ft_range_d}, {"log", test_ft_log},
{"llogof", test_ft_llogof}, {"ullogof", test_ft_ullogof},
{"logof", test_ft_logof}, {"min", test_ft_min},
{"max", test_ft_max}, {"pow", test_ft_pow}, {"round", test_ft_round},
{"sqrt", test_ft_sqrt}, {"clamp_f", test_ft_clamp_f},
{"clamp_d", test_ft_clamp_d}, {"align", test_ft_align},
{"align_2", test_ft_align_2}, {NULL, NULL}};
i = 0;
run_test(tests, &i);
return (i);
}

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_ft_abs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:20:34 by bgoulard #+# #+# */
/* Updated: 2024/05/23 23:21:18 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_abs(void)
{
int x;
x = -42;
if (ft_abs(x) != 42)
return (1);
x = 42;
if (ft_abs(x) != 42)
return (1);
x = 0;
if (ft_abs(x) != 0)
return (1);
return (0);
}

View file

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_align.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/26 19:53:26 by bgoulard #+# #+# */
/* Updated: 2024/07/06 17:05:07 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_align_2(void)
{
size_t size;
size_t result;
size = 42;
result = ft_align_2(size, 4);
if (result != 44)
return (1);
result = ft_align_2(size, 8);
if (result != 48)
return (2);
result = ft_align_2(size, 16);
if (result != 48)
return (3);
size = 275;
result = ft_align_2(size, 4);
if (result != 276)
return (4);
return (0);
}
int test_ft_align(void)
{
size_t size;
size_t result;
size = 42;
result = ft_align(size, 4);
if (result != 44)
return (1);
result = ft_align(size, 8);
if (result != 48)
return (2);
result = ft_align(size, 16);
if (result != 48)
return (3);
size = 275;
result = ft_align(size, 6);
if (result != 276)
return (4);
return (0);
}

View file

@ -0,0 +1,85 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_clamp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:46:19 by bgoulard #+# #+# */
/* Updated: 2024/05/28 09:12:26 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_clamp(void)
{
const int max = 42;
const int min = 21;
int x;
x = 0;
if (ft_clamp(x, min, max) != min)
return (1);
x = 21;
if (ft_clamp(x, min, max) != min)
return (1);
x = 42;
if (ft_clamp(x, min, max) != max)
return (1);
x = 84;
if (ft_clamp(x, min, max) != max)
return (1);
x = 23;
if (ft_clamp(x, min, max) != x)
return (1);
return (0);
}
int test_ft_clamp_f(void)
{
const float max = 42.0;
const float min = 21.0;
float x;
x = 0;
if (ft_clamp_f(x, min, max) != min)
return (1);
x = 21;
if (ft_clamp_f(x, min, max) != min)
return (1);
x = 42;
if (ft_clamp_f(x, min, max) != max)
return (1);
x = 84;
if (ft_clamp_f(x, min, max) != max)
return (1);
x = 23;
if (ft_clamp_f(x, min, max) != x)
return (1);
return (0);
}
int test_ft_clamp_d(void)
{
const double max = 42.0;
const double min = 21.0;
double x;
x = 0;
if (ft_clamp_d(x, min, max) != min)
return (1);
x = 21;
if (ft_clamp_d(x, min, max) != min)
return (1);
x = 42;
if (ft_clamp_d(x, min, max) != max)
return (1);
x = 84;
if (ft_clamp_d(x, min, max) != max)
return (1);
x = 23;
if (ft_clamp_d(x, min, max) != x)
return (1);
return (0);
}

View file

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_complex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:46:50 by bgoulard #+# #+# */
/* Updated: 2024/05/24 09:08:57 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
#include "ft_math_types.h"
int test_ft_complex_abs(void)
{
const t_complex x = {42, 0};
const t_complex y = {0, 42};
const t_complex z = {42, 42};
double res;
res = ft_complex_abs(x);
if (res < 41.99 || res > 42.01)
return (1);
res = ft_complex_abs(y);
if (res < 41.99 || res > 42.01)
return (2);
res = ft_complex_abs(z);
if (res < 59.39 || res > 59.41)
return (3);
return (0);
}
int test_ft_complex_addl(void)
{
const t_complex x = {42, 0};
const t_complex y = {0, 42};
t_complex res;
res = ft_complex_addl(x, 42);
if (res.real != 84 || res.imaginary != 42)
return (1);
res = ft_complex_addl(y, 42);
if (res.real != 42 || res.imaginary != 84)
return (1);
return (0);
}
int test_ft_complex_mull(void)
{
const t_complex x = {42, 0};
const t_complex y = {0, 42};
t_complex res;
res = ft_complex_mull(x, 2);
if (res.real != 84 || res.imaginary != 0)
return (1);
res = ft_complex_mull(y, 2);
if (res.real != 0 || res.imaginary != 84)
return (1);
return (0);
}
int test_ft_complex_muld(void)
{
const t_complex x = {42, 0};
const t_complex y = {0, 42};
t_complex res;
res = ft_complex_muld(x, 2.5);
if (res.real != 105 || res.imaginary != 0)
return (1);
res = ft_complex_muld(y, 2.5);
if (res.real != 0 || res.imaginary != 105)
return (1);
return (0);
}

View file

@ -0,0 +1,134 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_intrange.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:41:40 by bgoulard #+# #+# */
/* Updated: 2024/05/26 17:09:13 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_range_errors(void)
{
const int min = 9;
const int max = 42;
const int new_max = 21;
int x;
x = -1;
if (ft_range(x, min, max, new_max) != 0)
return (1);
x = min;
if (ft_range(x, min + max, max, new_max) != 0)
return (2);
x = max + 1;
if (ft_range(x, min, max, 0) != 0)
return (3);
return (0);
}
int test_ft_range(void)
{
const int min = 9;
const int max = 42;
const int new_max = 21;
int x;
x = -1;
if (ft_range(x, min, max, new_max) != 0)
return (1);
x = min;
if (ft_range(x, min, max, new_max) != 0)
return (2);
x = max + 1;
if (ft_range(x, max, max, new_max) != 0)
return (3);
if (ft_range(x, min, max, new_max) != new_max)
return (4);
x = 42;
if (ft_range(x, min, max, new_max) != new_max)
return (5);
x = 21;
if (ft_range(x, min, max, new_max) != (int)(((double)(x - min) / \
(max - min)) * new_max))
return (6);
return (test_ft_range_errors());
}
int test_ft_range_f(void)
{
const float min = 9.0f;
const float max = 42.0f;
const float new_max = 21.0f;
float x;
x = -1;
if (ft_range_f(x, min, max, new_max) != 0)
return (1);
x = min;
if (ft_range_f(x, min, max, new_max) != 0)
return (2);
x = max + 1;
if (ft_range_f(x, max, max, new_max) != 0)
return (3);
if (ft_range_f(x, min, max, new_max) != new_max)
return (4);
x = 42;
if (ft_range_f(x, min, max, new_max) != new_max)
return (5);
x = 21;
if (ft_range_f(x, min, max, new_max) != \
(float)(((double)(x - min) / (max - min)) * new_max))
return (6);
return (0);
}
int test_ft_range_d_errors(void)
{
const double min = 9.0;
const double max = 42.0;
const double new_max = 21.0;
double x;
x = -1;
if (ft_range_d(x, min, max, new_max) != 0)
return (1);
x = min;
if (ft_range_d(x, min + max, max, new_max) != 0)
return (2);
x = max + 1;
if (ft_range_d(x, min, max, 0) != 0)
return (3);
return (0);
}
int test_ft_range_d(void)
{
const double min = 9.0;
const double max = 42.0;
const double new_max = 21.0;
double x;
x = -1;
if (ft_range_d(x, min, max, new_max) != 0)
return (1);
x = min;
if (ft_range_d(x, min, max, new_max) != 0)
return (2);
x = max + 1;
if (ft_range_d(x, max, max, new_max) != 0)
return (3);
if (ft_range_d(x, min, max, new_max) != new_max)
return (4);
x = 42;
if (ft_range_d(x, min, max, new_max) != new_max)
return (5);
x = 21;
if (ft_range_d(x, min, max, new_max) != ((x - min) / (max - min)) * new_max)
return (6);
return (test_ft_range_d_errors());
}

View file

@ -0,0 +1,74 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_log.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:42:03 by bgoulard #+# #+# */
/* Updated: 2024/05/24 09:27:55 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_log(void)
{
int x;
x = 23;
if (ft_log(x) != 1)
return (1);
x = 0;
if (ft_log(x) != -1)
return (2);
x = 1;
if (ft_log(x) != 0)
return (3);
x = 420;
if (ft_log(x) != 2)
return (4);
x = -12;
if (ft_log(x) != -1)
return (5);
return (0);
}
int test_ft_llogof(void)
{
if (ft_llogof(0, 2) != -1)
return (1);
if (ft_llogof(1, 2) != 0)
return (2);
if (ft_llogof(2, 2) != 1)
return (3);
if (ft_llogof(8, 2) != 3)
return (4);
if (ft_llogof(23, 3) != 2)
return (5);
return (0);
}
int test_ft_ullogof(void)
{
if (ft_ullogof(0, 2) != -1)
return (1);
if (ft_ullogof(1, 2) != 0)
return (2);
if (ft_ullogof(2, 2) != 1)
return (3);
return (0);
}
int test_ft_logof(void)
{
if (ft_logof(0, 2) != -1)
return (1);
if (ft_logof(1, 2) != 0)
return (2);
if (ft_logof(2, 2) != 1)
return (3);
if (ft_logof(8, 2) != 3)
return (4);
return (0);
}

View file

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_minmax.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:49:30 by bgoulard #+# #+# */
/* Updated: 2024/05/24 00:54:36 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_min(void)
{
const int a = 1;
const int b = 2;
const int c = 3;
if (ft_min(a, b) != a)
return (1);
if (ft_min(b, c) != b)
return (1);
return (0);
}
int test_ft_max(void)
{
const int a = 1;
const int b = 2;
const int c = 3;
if (ft_max(a, b) != b)
return (1);
if (ft_max(c, b) != c)
return (1);
return (0);
}

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_pow.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:21:25 by bgoulard #+# #+# */
/* Updated: 2024/05/24 01:01:12 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_pow(void)
{
size_t x;
size_t y;
x = 2;
y = 3;
if (ft_pow(x, y) != 8)
return (1);
y = 0;
if (ft_pow(x, y) != 1)
return (1);
y = 1;
if (ft_pow(x, y) != 2)
return (1);
if (ft_pow(0, y) != 0)
return (1);
return (0);
}

View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_ft_round.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:24:56 by bgoulard #+# #+# */
/* Updated: 2024/05/23 23:25:46 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_round(void)
{
double x;
x = 42.42;
if (ft_round(x) != 42)
return (1);
x = 42.52;
if (ft_round(x) != 43)
return (1);
x = 42.499;
if (ft_round(x) != 42)
return (1);
x = 42.5;
if (ft_round(x) != 43)
return (1);
return (0);
}

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 23:49:48 by bgoulard #+# #+# */
/* Updated: 2024/05/24 09:34:56 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_math.h"
int test_ft_sqrt(void)
{
double x;
double result;
x = 4;
result = ft_sqrt(x);
if (result > 2.01 || result < 1.99)
return (1);
x = 2;
result = ft_sqrt(x);
if (result > 1.42 || result < 1.41)
return (2);
x = -1;
result = ft_sqrt(x);
if (result >= -0.99 || result <= -1.01)
return (3);
return (0);
}