Compare commits

30 Commits

Author SHA1 Message Date
airone01
3c607d8eb3 ci: patch verbosity of makefiles 2026-01-25 18:23:10 +01:00
Erwann Lagouche
677028dcbb Prettier output and some fixes (#4)
* feat: tab results

* feat: more colors

* style: norm

* fix: patch a spacing bug

* fix: patch a small issue

* fix: patch some leaks

* style: norm
2026-01-25 18:20:20 +01:00
d8824f7890 Add: itao + strdup tests 2026-01-25 17:41:52 +01:00
Erwann Lagouche
cf491b279d feat/stdout (#3)
* feat: disable standard output for tests

* fuck les fds

* patch some complation issues

* style: norm

* feat: timeout

* fix: patc more stuff

* fix: patch merge

* feat: more tests
2026-01-25 16:43:39 +01:00
442619f4cb FEAT: atoi and strncmp tests 2026-01-25 16:02:11 +01:00
5c9ddd84b7 ADD: bonus signal support 2026-01-25 12:28:27 +01:00
e2855ab2e7 FIX: Norminette OK 2026-01-25 12:06:54 +01:00
dd11abe7bb Merge branch 'feat/r1' 2026-01-25 12:00:09 +01:00
3ea3d8eace ADD: strncmp unit test 2026-01-25 11:50:29 +01:00
16b6a0c665 FIX: ft_atoi names + strncmp test WIP 2026-01-25 11:43:18 +01:00
airone01
c510913189 chore: small make changes 2026-01-24 19:05:21 +01:00
airone01
1ee5334149 syle: norm 2026-01-24 18:56:42 +01:00
airone01
932732c1e5 ci(make): force some targets 2026-01-24 18:52:13 +01:00
airone01
856739af67 refactor: fix the makefile problems 2026-01-24 18:46:05 +01:00
airone01
22de4eb11a refactor: move to framework dit 2026-01-24 17:12:11 +01:00
2f039c273c Add atoi tests 2026-01-24 17:06:45 +01:00
airone01
803127f57c fix: patch a libunit bug 2026-01-24 16:51:06 +01:00
airone01
88359c5262 feat: colors 2026-01-24 16:28:48 +01:00
airone01
6e652d3b24 ca fait bcp la non 2026-01-24 16:20:53 +01:00
airone01
1b48b0bb13 fix: makefile 2026-01-24 15:48:24 +01:00
airone01
e8c88da02d style: norm 2026-01-24 15:47:00 +01:00
airone01
760c91c949 feat: finally tests 2026-01-24 15:45:40 +01:00
ec0df49e52 fix some stuff 2026-01-24 15:26:42 +01:00
9b1896fb9a Merge branch 'launch_test' 2026-01-24 15:02:02 +01:00
3a062dc968 some fix 2026-01-24 15:01:35 +01:00
Erwann Lagouche
6ee228feac Merge pull request #1 from DavidGailleton/feat/util
feat/util
2026-01-24 14:40:21 +01:00
airone01
74ccfde56e style: norm 2026-01-24 14:39:08 +01:00
664ebef3b2 Merge branch 'feat/util' of github.com:DavidGailleton/42-LibUnit into launch_test 2026-01-24 14:27:07 +01:00
airone01
dda5944890 fix: patch a small bug 2026-01-24 14:10:46 +01:00
airone01
0605cb8c24 feat: initial commit 2026-01-24 13:48:33 +01:00
93 changed files with 2951 additions and 85 deletions

6
.gitignore vendored
View File

@@ -53,3 +53,9 @@ dkms.conf
# debug information files # debug information files
*.dwo *.dwo
/libunit
/real_tests/real_tests
/tests/tests
*.log

62
Makefile Normal file
View File

@@ -0,0 +1,62 @@
NAME = libunit.a
AR = ar rcs
CC = cc
MAKE += --no-print-directory
CCFLAGS = -Wall -Wextra -Werror -MMD -MP -g3
CCFLAGS += -I$(LIBFT_DIR) -I. -Iframework
LDFLAGS = -Llibft -lunit -lft -L.
LIBFT_DIR = libft
LIBFT_A = $(LIBFT_DIR)/libft.a
SRC = framework/libunit_util.c framework/libunit_util2.c framework/libunit.c framework/libunit_logger.c
OBJ = $(SRC:.c=.o)
TESTD = tests
TESTB = $(TESTD)/tests
TESTM = $(TESTD)/Makefile
RTESTD = real_tests
RTESTB = $(RTESTD)/real_tests
RTESTM = $(RTESTD)/Makefile
all: $(NAME)
$(NAME): $(OBJ) | $(LIBFT_A)
$(AR) $(NAME) $(OBJ)
%.o: %.c Makefile
$(CC) $(CCFLAGS) -c $< -o $@
$(LIBFT_A): FORCE
@$(MAKE) -C $(LIBFT_DIR)
clean:
$(RM) $(OBJ) $(SRC:.c=.d)
@$(MAKE) -C $(TESTD) clean
@$(MAKE) -C $(RTESTD) clean
@$(MAKE) -C $(LIBFT_DIR) clean
fclean: clean
$(RM) $(NAME)
@$(MAKE) -C $(TESTD) fclean
@$(MAKE) -C $(RTESTD) fclean
@$(MAKE) -C $(LIBFT_DIR) fclean
re: fclean all
@$(MAKE)
$(TESTB): FORCE
@$(MAKE) -C $(TESTD)
$(RTESTB): FORCE
@$(MAKE) -C $(RTESTD)
test: $(TESTB) $(RTESTB)
@$(TESTB)
@$(RTESTB)
FORCE: ;
-include $(SRC:.c=.d)
.PHONY: all clean fclean re

5
README Normal file
View File

@@ -0,0 +1,5 @@
libunit
=======
This is an implementation of the `libunit` 42 Rush project.

99
framework/libunit.c Normal file
View File

@@ -0,0 +1,99 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libunit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 12:43:35 by dgaillet #+# #+# */
/* Updated: 2026/01/25 18:15:25 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libunit.h"
#include <fcntl.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
static int parent_helper(int ffd, struct s_helper *h, const char *fn_name,
t_unit_test *test_list)
{
int status;
int ffdst[2];
pid_t caught_pid;
caught_pid = 0;
while (caught_pid != h->wpid)
{
caught_pid = wait(&status);
if (caught_pid < 0)
return (-1);
}
ffdst[0] = ffd;
ffdst[1] = status;
h->ok_tests += interpret_status(ffdst, fn_name, get_test_at(test_list,
h->i)->title, test_list->max_len);
return (0);
}
static int child_helper(t_unit_test *test_list, t_h h, int ffd)
{
int fd;
int res;
t_unit_test *test;
fd = open("/dev/null", O_WRONLY);
if (!fd)
return (-1);
if (dup2(fd, STDOUT_FILENO) < 0)
return (-1);
test = get_test_at(test_list, h.i);
if (test->timeout)
alarm(test->timeout);
res = test->func();
close(fd);
close(ffd);
clear_tests(&test_list);
exit(res);
}
static int handle_out(const char *fn_name)
{
char *tmp;
int fd;
tmp = ft_strjoin(fn_name, ".log");
if (!tmp)
return (-1);
fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0644);
free(tmp);
return (fd);
}
int launch_tests(t_unit_test *test_list, const char *fn_name)
{
int ffd;
t_h h;
h.ok_tests = 0;
h.i = -1;
ffd = handle_out(fn_name);
if (ffd < 0)
return (-1);
while (++h.i < (int)count_tests(test_list))
{
h.wpid = fork();
if (h.wpid < 0)
return (-1);
else if (h.wpid == 0 && child_helper(test_list, h, ffd) < 0)
return (-1);
else if (parent_helper(ffd, &h, fn_name, test_list))
return (-1);
}
print_passed_test(ffd, h.ok_tests, test_list);
close(ffd);
if (h.ok_tests != count_tests(test_list))
return (-1);
return (0);
}

84
framework/libunit.h Normal file
View File

@@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libunit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 14:38:40 by elagouch #+# #+# */
/* Updated: 2026/01/25 17:33:21 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBUNIT_H
# define LIBUNIT_H
# include "../libft/libft.h"
# include <sys/types.h>
# include <unistd.h>
/**
* @brief singular unit test def
*/
typedef struct s_unit_test
{
char *title;
int (*func)(void);
struct s_unit_test *next;
unsigned int timeout;
size_t max_len;
} t_unit_test;
/**
* @brief finds a test at index
*
* @return test or NULL
*/
t_unit_test *get_test_at(t_unit_test *head, size_t target_idx);
/**
* @brief count tests
*
* @return size_t test count
*/
size_t count_tests(t_unit_test *head);
/**
* @brief adds a new test
* @brief alternatively, if the passed head is empty, replace it with the
* initial test
*
* @param head_ptr pointer to the head of the tests list
* @param title name of the test
* @param test_func function to execute the test
*
* @return -1 on error, 0 on success
*/
size_t load_test(t_unit_test **head_ptr, const char *title,
int (*test_func)(void), unsigned int timeout);
/**
* @brief clears the tests memory
*/
void clear_tests(t_unit_test **head_ptr);
/**
* @brief launches the tests and returns the reported status
*/
int launch_tests(t_unit_test *test_list,
const char *fn_name);
typedef struct s_helper
{
pid_t wpid;
size_t ok_tests;
int i;
} t_h;
size_t interpret_status(int ffdst[2], const char *fn_name,
char *test_name, size_t spaces);
void print_passed_test(int ffd, size_t ok_tests,
t_unit_test *test_list);
#endif // !LIBUNIT_H

111
framework/libunit_logger.c Normal file
View File

@@ -0,0 +1,111 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libunit_logger.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 14:26:54 by elagouch #+# #+# */
/* Updated: 2026/01/25 17:35:53 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libunit.h"
#include <stdio.h>
static void print_tabbed(int fd1, int fd2, char *s, size_t expected_len)
{
size_t i;
size_t l;
l = ft_strlen(s);
ft_putstr_fd(s, fd1);
ft_putstr_fd(s, fd2);
i = 0;
while (l <= expected_len && i < (expected_len - l))
{
ft_putchar_fd(' ', fd1);
ft_putchar_fd(' ', fd2);
i++;
}
}
static void print_wtermsig(int ffd, int signal)
{
static char *sigs[15];
char *msg;
sigs[6] = "SIGABRT";
sigs[7] = "SIGBUS";
sigs[8] = "SIGFPE";
sigs[9] = "SIGKILL";
sigs[11] = "SIGSEGV";
sigs[13] = "SIGPIPE";
sigs[14] = "TIMEOUT";
ft_putstr_fd("[\x1B[33m", 1);
ft_putstr_fd("[", ffd);
if ((signal >= 6 && signal <= 9) || signal == 11 || (signal >= 13
&& signal <= 14))
msg = sigs[signal];
else
msg = "UNKNOWN";
ft_putstr_fd(msg, 1);
ft_putstr_fd(msg, ffd);
ft_putstr_fd("\x1B[0m]\n", 1);
ft_putstr_fd("]\n", ffd);
}
static void interpret_status_print(const char *fn_name, int ffd,
char *test_name, size_t max_len)
{
ft_putstr_fd("\x1B[94m", 1);
ft_putstr_fd((char *)fn_name, 1);
ft_putstr_fd((char *)fn_name, ffd);
ft_putstr_fd("\x1B[90m : \x1B[0m", 1);
ft_putstr_fd(" : ", ffd);
print_tabbed(1, ffd, test_name, max_len);
ft_putstr_fd("\x1B[90m : \x1B[0m", 1);
ft_putstr_fd(": ", ffd);
}
size_t interpret_status(int ffdst[2], const char *fn_name, char *test_name,
size_t max_len)
{
interpret_status_print(fn_name, ffdst[0], test_name, max_len);
if (WIFEXITED(ffdst[1]))
{
if (WEXITSTATUS(ffdst[1]))
{
ft_putstr_fd("[\x1B[31m\x1B[1mKO\x1B[0m]\n", 1);
ft_putstr_fd("[KO]\n", ffdst[0]);
}
else
{
ft_putstr_fd("[\x1B[32mOK\x1B[0m]\n", 1);
ft_putstr_fd("[OK]\n", ffdst[0]);
return (1);
}
}
else if (WIFSIGNALED(ffdst[1]))
print_wtermsig(ffdst[0], WTERMSIG(ffdst[1]));
return (0);
}
void print_passed_test(int ffd, size_t ok_tests, t_unit_test *test_list)
{
size_t total;
total = count_tests(test_list);
if (ok_tests == total)
ft_putstr_fd("\x1B[32m", 1);
else
ft_putstr_fd("\x1B[31m", 1);
ft_putnbr_fd(ok_tests, 1);
ft_putnbr_fd(ok_tests, ffd);
ft_putchar_fd('/', 1);
ft_putchar_fd('/', ffd);
ft_putnbr_fd((int)total, 1);
ft_putnbr_fd((int)total, ffd);
ft_putstr_fd("\x1B[0m tests passed\n\n", 1);
ft_putstr_fd(" tests passed\n\n", ffd);
}

99
framework/libunit_util.c Normal file
View File

@@ -0,0 +1,99 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libunit_util.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 14:35:57 by elagouch #+# #+# */
/* Updated: 2026/01/25 18:03:11 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libunit.h"
#include <stdlib.h>
size_t count_tests(t_unit_test *head)
{
size_t j;
j = 0;
while (head)
{
head = head->next;
j++;
}
return (j);
}
/**
* @brief util function to get last test of the chain
*/
t_unit_test *get_last(t_unit_test *head)
{
while (head->next)
head = head->next;
return (head);
}
/**
* @brief util function to allocate a new test
*/
static t_unit_test *alloc_test(const char *title, int (*test_func)(void),
unsigned int timeout)
{
t_unit_test *p;
p = malloc(sizeof(t_unit_test));
p->title = ft_strdup(title);
p->func = test_func;
p->next = NULL;
p->timeout = timeout;
p->max_len = 0;
return (p);
}
size_t load_test(t_unit_test **head_ptr, const char *title,
int (*test_func)(void), unsigned int timeout)
{
t_unit_test *last;
size_t tlen;
if (!head_ptr)
return (-1);
tlen = ft_strlen(title);
if (!*head_ptr)
{
*head_ptr = alloc_test(title, test_func, timeout);
if (!*head_ptr)
return (-1);
(*head_ptr)->max_len = ft_strlen(title);
return (0);
}
last = get_last(*head_ptr);
last->next = alloc_test(title, test_func, timeout);
if (!last->next)
return (-1);
if ((*head_ptr)->max_len < tlen)
(*head_ptr)->max_len = tlen;
return (0);
}
void clear_tests(t_unit_test **head_ptr)
{
t_unit_test *current;
t_unit_test *next;
if (!head_ptr)
return ;
current = *head_ptr;
while (current)
{
next = current->next;
if (current->title)
free(current->title);
free(current);
current = next;
}
*head_ptr = NULL;
}

28
framework/libunit_util2.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libunit_util2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:46:43 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:15:43 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libunit.h"
/* we loop over instead of shifting the pointer to make sure we don't skip
unexisting tests and end up in unallocated/invalid memory */
t_unit_test *get_test_at(t_unit_test *head, size_t target_idx)
{
size_t j;
j = 0;
while ((j < target_idx) && head)
{
head = head->next;
j++;
}
return (head);
}

View File

@@ -1,85 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 12:43:35 by dgaillet #+# #+# */
/* Updated: 2026/01/24 12:43:37 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libunit.h"
#include "libft.h"
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
static int test_func(t_unit_test *test_node)
{
int res;
res = test_node->func;
}
static size_t interpret_status(int status, const char *fn_name, char *test_name)
{
ft_putstr_fd(fn_name, 1);
ft_putstr_fd(" : ", 1);
ft_putstr_fd(test_name, 1);
ft_putstr_fd(" : ", 1);
if (WIFEXITED(status))
{
if (WEXITSTATUS(status))
ft_putstr_fd("[KO]\n", 1);
else
{
ft_putstr_fd("[OK]\n", 1);
return (1);
}
}
else if (WIFSIGNALED(status))
{
if (WTERMSIG(status) == 11)
ft_putstr_fd("[SIGSEGV]\n", 1);
else if (WTERMSIG(status) == 10)
ft_putstr_fd("[SIGBUS]\n", 1);
}
return (0);
}
static void print_passed_test(size_t ok_tests, t_unit_test *test_list)
{
ft_putnbr_fd(ok_tests, 1);
ft_putchar_fd('/', 1);
ft_putnbr_fd(total_node(test_list));
ft_putstr_fd(" tests checked", 1);
}
int launch_tests(t_unit_test *test_list, const char *fn_name)
{
size_t ok_tests;
pid_t wpid;
int status;
ok_tests = 0;
while (1)
{
wpid = fork();
if (wpid < 0)
return (1);
else if (wpid == 0)
test_func(test_func);
else
{
wpid = wait(&status);
if (wpid < 0)
return (1);
ok_tests += interpret_status(test_node, wpid, status);
}
}
print_passed_test(ok_tests, test_list);
return (0);
}

57
libft/.gitignore vendored Normal file
View File

@@ -0,0 +1,57 @@
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# debug information files
*.dwo
libft.a

94
libft/Makefile Normal file
View File

@@ -0,0 +1,94 @@
CC= cc
AR= ar
ARFLAGS= rcs
HEADER= libft.h
CFLAGS= -Wall \
-Wextra \
-Werror
NAME= libft.a
SRC= ft_isdigit.c \
ft_isalpha.c \
ft_isalnum.c \
ft_isascii.c \
ft_isprint.c \
ft_strlen.c \
ft_memset.c \
ft_bzero.c \
ft_memcpy.c \
ft_memmove.c \
ft_strlcpy.c \
ft_strlcat.c \
ft_toupper.c \
ft_tolower.c \
ft_strchr.c \
ft_strrchr.c \
ft_strncmp.c \
ft_memcmp.c \
ft_memchr.c \
ft_strnstr.c \
ft_atoi.c \
ft_calloc.c \
ft_strdup.c \
ft_substr.c \
ft_strjoin.c \
ft_strtrim.c \
ft_split.c \
ft_itoa.c \
ft_strmapi.c \
ft_striteri.c \
ft_putchar_fd.c \
ft_putstr_fd.c \
ft_putendl_fd.c \
ft_putnbr_fd.c
BONUS_SRC= ft_lstnew_bonus.c \
ft_lstadd_front_bonus.c \
ft_lstsize_bonus.c \
ft_lstlast_bonus.c \
ft_lstadd_back_bonus.c \
ft_lstdelone_bonus.c \
ft_lstclear_bonus.c \
ft_lstiter_bonus.c \
ft_lstmap_bonus.c
OBJ= $(SRC:.c=.o)
BONUS_OBJ= $(BONUS_SRC:.c=.o)
DEP= $(SRC:.c=.d)
BONUS_DEP= $(BONUS_SRC:.c=.d)
ALL_OBJ= $(OBJ) $(BONUS_OBJ)
ALL_DEP= $(DEP) $(BONUS_DEP)
%.o: %.c
$(CC) -MMD -MP -o $@ -c $< $(CFLAGS) -I$(HEADER)
all: $(NAME)
$(NAME): $(OBJ)
$(AR) $(ARFLAGS) $(NAME) $(OBJ)
bonus:
$(MAKE) $(NAME) SRC="$(SRC) $(BONUS_SRC)"
clean:
rm -f $(ALL_OBJ) $(ALL_DEP)
fclean: clean
rm -f $(NAME)
re: fclean all
-include $(DEP)
.PHONY: all clean fclean re bonus

62
libft/ft_atoi.c Normal file
View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 19:07:51 by dgaillet #+# #+# */
/* Updated: 2025/11/12 14:17:18 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static long long int str_to_ll(const char *nptr)
{
int i;
long long int res;
i = 0;
res = 0;
while (ft_isdigit(nptr[i]))
{
if (res * 10 < res && res > 0)
return (-1);
res = (10 * res) + nptr[i] - 48;
i++;
}
return (res);
}
static long long int ft_atoll(const char *nptr)
{
int i;
long long int res;
i = 0;
res = 0;
if (!nptr[0])
return (0);
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == ' ')
i++;
if (nptr[i] == '-' && ft_isdigit(nptr[i + 1]))
{
res = -1 * ft_atoll(&nptr[i] + 1);
if ((nptr[i + 1] != '1' && res == 1) || (nptr[i + 1] == '1'
&& ft_isdigit(nptr[i + 2]) && res == 1))
return (0);
return (res);
}
else if (nptr[i] == '+' && ft_isdigit(nptr[i + 1]))
i++;
return (str_to_ll(&nptr[i]));
}
int ft_atoi(const char *nptr)
{
int res;
res = (int)ft_atoll(nptr);
return (res);
}

23
libft/ft_bzero.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 11:41:08 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:54:13 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
while (n > 0)
{
*((unsigned char *)s) = '\0';
s++;
n--;
}
}

26
libft/ft_calloc.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 19:26:10 by dgaillet #+# #+# */
/* Updated: 2025/11/12 17:05:12 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *all_mem;
if (size && nmemb > SIZE_MAX / size)
return (NULL);
all_mem = malloc(size * nmemb);
if (!all_mem)
return (NULL);
ft_bzero(all_mem, nmemb * size);
return (all_mem);
}

20
libft/ft_isalnum.c Normal file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 10:46:12 by dgaillet #+# #+# */
/* Updated: 2025/11/05 10:47:18 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
if (ft_isalpha(c) || ft_isdigit(c))
return (1);
return (0);
}

18
libft/ft_isalpha.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 09:53:19 by dgaillet #+# #+# */
/* Updated: 2025/11/06 09:48:22 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
int ft_isalpha(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return (1);
return (0);
}

18
libft/ft_isascii.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 10:48:02 by dgaillet #+# #+# */
/* Updated: 2025/11/05 10:50:20 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
return (0);
}

18
libft/ft_isdigit.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 09:57:01 by dgaillet #+# #+# */
/* Updated: 2025/11/11 15:45:19 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
if (c >= '0' && c <= '9')
return (1);
return (0);
}

18
libft/ft_isprint.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 11:14:13 by dgaillet #+# #+# */
/* Updated: 2025/11/06 10:04:03 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int c)
{
if (c >= 32 && c <= 126)
return (1);
return (0);
}

62
libft/ft_itoa.c Normal file
View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/07 13:06:35 by dgaillet #+# #+# */
/* Updated: 2025/11/12 14:20:16 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t count_digits(int n)
{
size_t size;
size = 0;
if (n <= 0)
size++;
while (n)
{
n /= 10;
size++;
}
return (size);
}
static void insert_char(char *str, unsigned int nbr, size_t index)
{
while (nbr)
{
str[index--] = nbr % 10 + '0';
nbr /= 10;
}
}
char *ft_itoa(int n)
{
unsigned int nbr;
char *str;
size_t size;
nbr = n;
if (n < 0)
nbr = n * -1;
size = count_digits(n);
str = malloc(sizeof(char) * (size + 1));
if (!str)
return (NULL);
str[size] = '\0';
if (nbr == 0)
str[0] = '0';
else
{
if (n < 0)
str[0] = '-';
insert_char(str, nbr, size - 1);
}
return (str);
}

View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 15:06:49 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:11:12 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *temp;
if (!lst)
return ;
if (!(*lst))
{
*lst = new;
return ;
}
temp = ft_lstlast(*lst);
temp->next = new;
}

View File

@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 14:36:17 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:14:35 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (!new || !lst)
return ;
new->next = *lst;
*lst = new;
}

34
libft/ft_lstclear_bonus.c Normal file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 15:31:17 by dgaillet #+# #+# */
/* Updated: 2025/11/12 17:07:13 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *temp;
t_list *next;
if (!lst || !*lst)
return ;
temp = *lst;
next = temp->next;
while (next)
{
del(temp->content);
free(temp);
temp = next;
next = temp->next;
}
del(temp->content);
free(temp);
*lst = NULL;
}

View File

@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 15:22:02 by dgaillet #+# #+# */
/* Updated: 2025/11/12 17:07:58 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (!lst || !del)
return ;
del(lst->content);
free(lst);
}

24
libft/ft_lstiter_bonus.c Normal file
View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 15:51:31 by dgaillet #+# #+# */
/* Updated: 2025/11/12 15:54:18 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!f)
return ;
while (lst)
{
f(lst->content);
lst = lst->next;
}
}

30
libft/ft_lstlast_bonus.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 15:03:19 by dgaillet #+# #+# */
/* Updated: 2025/11/11 15:18:37 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
size_t size;
size_t i;
if (!lst)
return (NULL);
size = ft_lstsize(lst);
i = 1;
while (i < size)
{
lst = lst->next;
i++;
}
return (lst);
}

38
libft/ft_lstmap_bonus.c Normal file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 15:54:38 by dgaillet #+# #+# */
/* Updated: 2025/11/10 18:19:21 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_lst;
t_list *temp_lst;
void *temp_content;
if (!lst)
return (NULL);
new_lst = NULL;
while (lst)
{
temp_content = f(lst->content);
temp_lst = ft_lstnew(temp_content);
if (!temp_lst)
{
del(temp_content);
ft_lstclear(&new_lst, del);
return (NULL);
}
ft_lstadd_back(&new_lst, temp_lst);
lst = lst->next;
}
return (new_lst);
}

25
libft/ft_lstnew_bonus.c Normal file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 14:27:21 by dgaillet #+# #+# */
/* Updated: 2025/11/10 18:19:27 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *new_lst;
new_lst = malloc(sizeof(t_list));
if (!new_lst)
return (NULL);
new_lst->content = content;
new_lst->next = NULL;
return (new_lst);
}

32
libft/ft_lstsize_bonus.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/09 14:43:22 by dgaillet #+# #+# */
/* Updated: 2025/11/11 11:31:23 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
t_list *first_node;
if (!lst)
return (0);
first_node = lst;
i = 1;
while (lst->next)
{
lst = lst->next;
if (lst == first_node)
break ;
i++;
}
return (i);
}

28
libft/ft_memchr.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 17:54:17 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:56:15 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
void *ptr;
ptr = (void *)s;
while (n > 0)
{
if (*((unsigned char *)ptr) == (unsigned char)c)
return (ptr);
ptr++;
n--;
}
return (NULL);
}

29
libft/ft_memcmp.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 18:00:38 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:54:27 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
if (((unsigned char *)s1)[i] > ((unsigned char *)s2)[i])
return (1);
if (((unsigned char *)s1)[i] < ((unsigned char *)s2)[i])
return (-1);
i++;
}
return (0);
}

28
libft/ft_memcpy.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 11:46:16 by dgaillet #+# #+# */
/* Updated: 2025/11/12 14:24:38 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t n)
{
size_t i;
if (!dest && !src)
return (dest);
i = 0;
while (i < n)
{
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
i++;
}
return (dest);
}

34
libft/ft_memmove.c Normal file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 13:17:42 by dgaillet #+# #+# */
/* Updated: 2025/11/09 20:15:29 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void *ft_rev_memcpy(void *dest, const void *src, size_t n)
{
if ((!dest && !src) || n == 0)
return (dest);
n--;
while (n > 0)
{
((unsigned char *)dest)[n] = ((unsigned char *)src)[n];
n--;
}
((unsigned char *)dest)[n] = ((unsigned char *)src)[n];
return (dest);
}
void *ft_memmove(void *dest, const void *src, size_t n)
{
if (dest < src)
return (ft_memcpy(dest, src, n));
return (ft_rev_memcpy(dest, src, n));
}

26
libft/ft_memset.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 11:20:47 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:54:07 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
((unsigned char *)s)[i] = c;
i++;
}
return (s);
}

18
libft/ft_putchar_fd.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/08 17:41:14 by dgaillet #+# #+# */
/* Updated: 2025/11/11 13:54:54 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

20
libft/ft_putendl_fd.c Normal file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/08 17:46:08 by dgaillet #+# #+# */
/* Updated: 2025/11/11 12:25:15 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <unistd.h>
void ft_putendl_fd(char *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

35
libft/ft_putnbr_fd.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/08 17:50:35 by dgaillet #+# #+# */
/* Updated: 2025/11/11 12:26:48 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void write_nbr(unsigned int n, int fd)
{
if (n)
{
write_nbr(n / 10, fd);
ft_putchar_fd(n % 10 + '0', fd);
}
}
void ft_putnbr_fd(int n, int fd)
{
if (!n)
ft_putchar_fd('0', fd);
else if (n < 0)
{
ft_putchar_fd('-', fd);
write_nbr(n * -1, fd);
}
else
write_nbr(n, fd);
}

18
libft/ft_putstr_fd.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/08 17:43:42 by dgaillet #+# #+# */
/* Updated: 2025/11/11 13:56:30 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
write(fd, s, ft_strlen(s));
}

81
libft/ft_split.c Normal file
View File

@@ -0,0 +1,81 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/06 17:02:58 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:30:49 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t strs_size(const char *s, unsigned char c)
{
int i;
int j;
i = 0;
j = 0;
while (s[j])
{
if ((s[j] != c && j == 0) || (s[j] != c && s[j - 1] == c))
i++;
j++;
}
return (i);
}
static int next_match(char *str, unsigned char c)
{
int i;
i = 0;
while (str[i] && str[i] != c)
i++;
return (i);
}
static void clear_strs(char **strs)
{
size_t i;
i = 0;
while (strs[i])
{
free(strs[i]);
i++;
}
free(strs);
}
char **ft_split(char const *s, char c)
{
char **strs;
int i;
int j;
if (!s)
return (NULL);
strs = ft_calloc(sizeof(char *), strs_size(s, c) + 1);
if (!strs)
return (NULL);
i = 0;
j = 0;
while (s[j])
{
if ((s[j] != c && j == 0) || (s[j] != c && s[j - 1] == c))
{
strs[i] = ft_substr(&s[j], 0, next_match((char *)&s[j], c));
if (!strs[i++])
{
clear_strs(strs);
return (NULL);
}
}
j++;
}
return (strs);
}

29
libft/ft_strchr.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 17:24:37 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:54:20 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
int i;
i = 0;
while (s[i])
{
if ((unsigned char)s[i] == (unsigned char)c)
return ((char *)s + i);
i++;
}
if ((unsigned char)s[i] == (unsigned char)c)
return ((char *)s + i);
return (NULL);
}

31
libft/ft_strdup.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 19:31:29 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:54:36 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *dest;
int i;
dest = malloc(sizeof(char) * (ft_strlen(s) + 1));
if (!dest)
return (NULL);
i = 0;
while (s[i])
{
dest[i] = s[i];
i++;
}
dest[i] = '\0';
return (dest);
}

25
libft/ft_striteri.c Normal file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/08 17:36:38 by dgaillet #+# #+# */
/* Updated: 2025/11/12 17:21:21 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
unsigned int i;
if (!f)
return ;
i = 0;
while (s[i])
{
f(i, &s[i]);
i++;
}
}

38
libft/ft_strjoin.c Normal file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/06 13:52:21 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:36:32 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
int i;
int j;
str = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
if (!str)
return (NULL);
i = 0;
j = 0;
while (s1[i])
{
str[i] = s1[i];
i++;
}
while (s2[j])
{
str[i + j] = s2[j];
j++;
}
str[i + j] = '\0';
return (str);
}

33
libft/ft_strlcat.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 17:11:43 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:38:24 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
size_t j;
i = 0;
j = ft_strlen(dst);
if (!size)
return (ft_strlen(src));
if (j >= size)
return (ft_strlen(src) + size);
while (src[i] && i < ((size - j) - 1))
{
dst[i + j] = src[i];
i++;
}
dst[i + j] = '\0';
return (j + ft_strlen(src));
}

30
libft/ft_strlcpy.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 13:31:13 by dgaillet #+# #+# */
/* Updated: 2025/11/06 12:05:04 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i;
i = 0;
if (size > 0)
{
while (src[i] && i < (size - 1))
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
}
return (ft_strlen(src));
}

23
libft/ft_strlen.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 11:17:31 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:36:18 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i])
i++;
return (i);
}

33
libft/ft_strmapi.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/08 17:30:25 by dgaillet #+# #+# */
/* Updated: 2025/11/12 17:22:49 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
unsigned int i;
if (!s || !f)
return (NULL);
i = 0;
str = malloc(sizeof(char) * (ft_strlen(s) + 1));
if (!str)
return (NULL);
while (s[i])
{
str[i] = f(i, s[i]);
i++;
}
str[i] = '\0';
return (str);
}

29
libft/ft_strncmp.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 17:34:15 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:41:15 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
while ((s1[i] || s2[i]) && i < n)
{
if ((unsigned char)s1[i] > (unsigned char)s2[i])
return (1);
if ((unsigned char)s1[i] < (unsigned char)s2[i])
return (-1);
i++;
}
return (0);
}

33
libft/ft_strnstr.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 18:05:52 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:42:42 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t little_len;
size_t big_len;
size_t i;
i = 0;
little_len = ft_strlen(little);
big_len = ft_strlen(big);
if (!little[0])
return ((char *)big);
while ((little_len + i) <= len && (little_len + i) <= big_len)
{
if (!ft_strncmp(&big[i], little, little_len))
return ((char *)&big[i]);
i++;
}
return (NULL);
}

29
libft/ft_strrchr.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 17:28:39 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:43:49 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *s, int c)
{
int i;
i = 0;
while (s[i])
i++;
while (i >= 0)
{
if ((unsigned char)s[i] == (unsigned char)c)
return ((char *)&s[i]);
i--;
}
return (NULL);
}

87
libft/ft_strtrim.c Normal file
View File

@@ -0,0 +1,87 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/06 16:31:38 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:50:53 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int test_charset(char c, char const *set)
{
if (!set[0])
return (0);
if (c == set[0])
return (1);
return (test_charset(c, set + 1));
}
static size_t end_trim(char const *s1, char const *set)
{
int i;
i = 0;
if (!s1[0])
return (0);
while (s1[i])
i++;
i--;
while (test_charset(s1[i], set))
i--;
return (i);
}
static size_t start_trim(char const *s1, char const *set)
{
size_t i;
i = 0;
while (test_charset(s1[i], set))
i++;
return (i);
}
static int is_empty(char const *s1, char const *set)
{
size_t i;
i = 0;
while (s1[i])
{
if (!test_charset(s1[i], set))
return (0);
i++;
}
return (1);
}
char *ft_strtrim(char const *s1, char const *set)
{
size_t start;
size_t end;
size_t i;
char *str;
if (!s1 || !set)
return (NULL);
i = 0;
if (is_empty(s1, set))
return (ft_calloc(1, sizeof(char)));
start = start_trim(s1, set);
end = end_trim(s1, set);
str = malloc(sizeof(char) * (end - start + 2));
if (!str)
return (NULL);
while (start + i <= end)
{
str[i] = s1[i + start];
i++;
}
str[i] = '\0';
return (str);
}

39
libft/ft_substr.c Normal file
View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/06 13:20:55 by dgaillet #+# #+# */
/* Updated: 2025/11/12 13:51:23 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
size_t i;
char *sub_str;
size_t s_len;
if (!s)
return (NULL);
s_len = ft_strlen(s);
if (start > s_len)
len = 0;
else if (s_len < (start + len))
len = s_len - start;
sub_str = malloc(sizeof(char) * (len + 1));
if (!sub_str)
return (NULL);
i = 0;
while (i < len)
{
sub_str[i] = s[start + i];
i++;
}
sub_str[i] = '\0';
return (sub_str);
}

18
libft/ft_tolower.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 17:23:29 by dgaillet #+# #+# */
/* Updated: 2025/11/05 17:24:21 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
int ft_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return (c + 32);
return (c);
}

18
libft/ft_toupper.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 17:20:43 by dgaillet #+# #+# */
/* Updated: 2025/11/05 17:23:02 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
int ft_toupper(int c)
{
if (c >= 'a' && c <= 'z')
return (c - 32);
return (c);
}

74
libft/libft.h Normal file
View File

@@ -0,0 +1,74 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/05 09:49:43 by dgaillet #+# #+# */
/* Updated: 2026/01/24 13:40:18 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <limits.h>
# include <stdint.h>
# include <stdlib.h>
# include <unistd.h>
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
int ft_isalpha(int c);
int ft_isdigit(int c);
int ft_isalnum(int c);
int ft_isascii(int c);
int ft_isprint(int c);
size_t ft_strlen(const char *s);
void *ft_memset(void *s, int c, size_t n);
void ft_bzero(void *s, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t n);
void *ft_memmove(void *dest, const void *src, size_t n);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
int ft_toupper(int c);
int ft_tolower(int c);
char *ft_strchr(const char *s, int c);
char *ft_strrchr(const char *s, int c);
int ft_strncmp(const char *s1, const char *s2, size_t n);
int ft_memcmp(const void *s1, const void *s2, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
char *ft_strnstr(const char *big, const char *little,
size_t len);
int ft_atoi(const char *nptr);
void *ft_calloc(size_t nmemb, size_t size);
char *ft_strdup(const char *s);
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
char *ft_itoa(int n);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*f)(unsigned int, char *));
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char *s, int fd);
void ft_putendl_fd(char *s, int fd);
void ft_putnbr_fd(int n, int fd);
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *new_);
int ft_lstsize(t_list *lst);
t_list *ft_lstlast(t_list *lst);
void ft_lstadd_back(t_list **lst, t_list *new_);
void ft_lstdelone(t_list *lst, void (*del)(void *));
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *),
void (*del)(void *));
char *ft_lltoa(long long n);
#endif

41
real_tests/Makefile Normal file
View File

@@ -0,0 +1,41 @@
NAME = real_tests
CC = cc
MAKE += --no-print-directory
CCFLAGS = -Wall -Wextra -Werror -MMD -MP
SRC = main.c
SRC += ft_strlen/00_launcher.c ft_strlen/01_basic.c ft_strlen/02_null.c ft_strlen/03_large.c
SRC += ft_atoi/00_launcher.c ft_atoi/01_basic.c ft_atoi/02_int_max.c ft_atoi/03_int_min.c ft_atoi/04_null.c
SRC += ft_strncmp/00_launcher.c ft_strncmp/01_basic.c ft_strncmp/02_len.c ft_strncmp/03_high_len.c
SRC += ft_strdup/00_launcher.c ft_strdup/01_basic.c ft_strdup/02_null.c
SRC += ft_itoa/00_launcher.c ft_itoa/01_positif.c ft_itoa/02_negatif.c ft_itoa/03_zero.c ft_itoa/04_int_max.c ft_itoa/05_int_min.c
OBJ = $(SRC:.c=.o)
LIBS = -L.. -lunit -L../libft -lft
INC = -I. -I../framework -I../libft
all: $(NAME)
test: $(NAME)
./$(NAME)
%.o: %.c Makefile
$(CC) $(CCFLAGS) $(INC) -c $< -o $@
$(NAME): $(OBJ) | libunit
$(CC) $(CCFLAGS) $(INC) $(OBJ) $(LIBS) -o $(NAME)
libunit:
@$(MAKE) -C ..
clean:
$(RM) $(OBJ) $(SRC:.c=.d)
fclean: clean
$(RM) $(NAME)
re: fclean all
-include $(SRC:.c=.d)
.PHONY: all clean fclean re libunit

View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 16:22:35 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:32:35 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int atoi_launcher(void)
{
t_unit_test *testlist;
size_t res;
testlist = NULL;
load_test(&testlist, "Basic test", &atoi_basic_test, 0);
load_test(&testlist, "INT MAX test", &atoi_int_max_test, 0);
load_test(&testlist, "INT MIN test", &atoi_int_min_test, 0);
load_test(&testlist, "NULL test", &atoi_null_test, 0);
res = launch_tests(testlist, "atoi");
clear_tests(&testlist);
return (res);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_basic.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 17:22:48 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:33:19 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
#include "libft.h"
int atoi_basic_test(void)
{
return (!(ft_atoi("42") == 42));
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_int_max.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 17:23:00 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:33:35 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int atoi_int_max_test(void)
{
return (!(ft_atoi("2147483647") == 2147483647));
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 03_int_min.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 17:23:10 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:33:46 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int atoi_int_min_test(void)
{
return (!(ft_atoi("-2147483648") == -2147483648));
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 04_null.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:33:31 by elagouch #+# #+# */
/* Updated: 2026/01/25 17:33:32 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int atoi_null_test(void)
{
return (ft_atoi(NULL) == 0);
}

View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:12:06 by dgaillet #+# #+# */
/* Updated: 2026/01/25 17:12:07 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int itoa_launcher(void)
{
t_unit_test *testlist;
size_t res;
testlist = NULL;
load_test(&testlist, "Positif test", &itoa_positif_test, 0);
load_test(&testlist, "Negatif test", &itoa_negatif_test, 0);
load_test(&testlist, "Zero test", &itoa_zero_test, 0);
load_test(&testlist, "INT MAX test", &itoa_int_max_test, 0);
load_test(&testlist, "INT MIN test", &itoa_int_max_test, 0);
res = launch_tests(testlist, "itoa");
clear_tests(&testlist);
return (res);
}

View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_positif.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:12:19 by dgaillet #+# #+# */
/* Updated: 2026/01/25 17:12:20 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int itoa_positif_test(void)
{
char *str;
int res;
str = ft_itoa(42);
res = ft_strncmp(str, "42", 10);
free(str);
return (res);
}

View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_negatif.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:12:34 by dgaillet #+# #+# */
/* Updated: 2026/01/25 17:12:34 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int itoa_negatif_test(void)
{
char *str;
int res;
str = ft_itoa(-42);
res = ft_strncmp(str, "-42", 10);
free(str);
return (res);
}

View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 03_zero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:12:43 by dgaillet #+# #+# */
/* Updated: 2026/01/25 17:12:44 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int itoa_zero_test(void)
{
char *str;
int res;
str = ft_itoa(0);
res = ft_strncmp(str, "0", 10);
free(str);
return (res);
}

View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 04_int_max.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:12:57 by dgaillet #+# #+# */
/* Updated: 2026/01/25 17:12:58 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int itoa_int_max_test(void)
{
char *str;
int res;
str = ft_itoa(2147483647);
res = ft_strncmp(str, "2147483647", 15);
free(str);
return (res);
}

View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 05_int_min.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:13:07 by dgaillet #+# #+# */
/* Updated: 2026/01/25 17:13:09 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int itoa_int_min_test(void)
{
char *str;
int res;
str = ft_itoa(-2147483648);
res = ft_strncmp(str, "-2147483648", 15);
free(str);
return (res);
}

View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 16:56:28 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:56:28 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int strdup_launcher(void)
{
t_unit_test *testlist;
size_t res;
testlist = NULL;
load_test(&testlist, "Basic test", &strdup_basic_test, 0);
load_test(&testlist, "Basic test", &strdup_null_test, 0);
res = launch_tests(testlist, "strdup");
clear_tests(&testlist);
return (res);
}

View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_basic.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:10:35 by dgaillet #+# #+# */
/* Updated: 2026/01/25 17:10:36 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
#include <stdlib.h>
int strdup_basic_test(void)
{
char *str;
int res;
str = ft_strdup("Hello, World !");
res = ft_strncmp(str, "Hello, World !", 14);
free(str);
return (res);
}

View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_null.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 17:10:43 by dgaillet #+# #+# */
/* Updated: 2026/01/25 17:10:44 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
#include <stdlib.h>
int strdup_null_test(void)
{
char *str;
str = ft_strdup(NULL);
if (str)
free(str);
return (1);
}

View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */
/* Updated: 2026/01/25 15:13:57 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int strlen_launcher(void)
{
t_unit_test *testlist;
size_t res;
testlist = NULL;
load_test(&testlist, "null", &test_null, 0);
load_test(&testlist, "basic", &test_basic, 0);
load_test(&testlist, "large", &test_large, 0);
res = launch_tests(testlist, "strlen");
clear_tests(&testlist);
return (res);
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_basic.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 15:16:59 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int test_basic(void)
{
return (!(ft_strlen("hello, world") == 12));
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_null.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 15:16:28 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int test_null(void)
{
return (!(ft_strlen(NULL) == 0));
}

View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 03_large.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 15:16:42 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int test_large(void)
{
size_t i;
char s[10000];
i = 0;
while (i < sizeof(s))
{
s[i] = ' ';
i++;
}
return (!(ft_strlen(s) == sizeof(s) + 1));
}

View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 12:05:05 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:35:04 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int strncmp_launcher(void)
{
t_unit_test *testlist;
size_t res;
testlist = NULL;
load_test(&testlist, "Basic test", &strncmp_basic_test, 0);
load_test(&testlist, "Len test", &strncmp_len_test, 0);
load_test(&testlist, "High len test", &strncmp_high_len_test, 0);
res = launch_tests(testlist, "ft_strncmp");
clear_tests(&testlist);
return (res);
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_ok.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 12:05:24 by dgaillet #+# #+# */
/* Updated: 2026/01/25 15:15:39 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int strncmp_basic_test(void)
{
return (ft_strncmp("test", "test", 4));
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_len.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 12:05:30 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:34:24 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int strncmp_len_test(void)
{
return (ft_strncmp("test123", "test", 4));
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 03_high_len.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 16:01:01 by dgaillet #+# #+# */
/* Updated: 2026/01/25 16:35:34 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int strncmp_high_len_test(void)
{
return (ft_strncmp("test", "test", 42));
}

22
real_tests/main.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 18:53:18 by elagouch #+# #+# */
/* Updated: 2026/01/24 18:53:18 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests.h"
int main(void)
{
strlen_launcher();
atoi_launcher();
strncmp_launcher();
strdup_launcher();
itoa_launcher();
}

52
real_tests/tests.h Normal file
View File

@@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */
/* Updated: 2026/01/24 18:40:48 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TESTS_H
# define TESTS_H
# include "libunit.h"
// LAUNCHERS
int strlen_launcher(void);
int atoi_launcher(void);
int strncmp_launcher(void);
int strdup_launcher(void);
int itoa_launcher(void);
// strlen
int test_basic(void);
int test_null(void);
int test_large(void);
// atoi
int atoi_basic_test(void);
int atoi_int_max_test(void);
int atoi_int_min_test(void);
int atoi_null_test(void);
// strncmp
int strncmp_basic_test(void);
int strncmp_len_test(void);
int strncmp_high_len_test(void);
//strdup
int strdup_basic_test(void);
int strdup_null_test(void);
//itao
int itoa_positif_test(void);
int itoa_negatif_test(void);
int itoa_zero_test(void);
int itoa_int_max_test(void);
int itoa_int_min_test(void);
#endif // !TESTS_H

37
tests/Makefile Normal file
View File

@@ -0,0 +1,37 @@
NAME = tests
CC = cc
MAKE += --no-print-directory
CCFLAGS = -Wall -Wextra -Werror -MMD -MP -g3
SRC = main.c
SRC += libunit/00_launcher.c libunit/01_ok.c libunit/02_ko.c libunit/03_sigsegv.c libunit/04_sigbus.c libunit/05_sigkill.c libunit/06_sigabrt.c libunit/07_sigfpe.c libunit/08_sigpipe.c libunit/09_timeout.c
OBJ = $(SRC:.c=.o)
LIBS = -L.. -lunit -L../libft -lft
INC = -I. -I../framework -I../libft
all: $(NAME)
test: $(NAME)
./$(NAME)
%.o: %.c Makefile
$(CC) $(CCFLAGS) $(INC) -c $< -o $@
$(NAME): $(OBJ) | libunit
$(CC) $(CCFLAGS) $(INC) $(OBJ) $(LIBS) -o $(NAME)
libunit:
@$(MAKE) -C ..
clean:
$(RM) $(OBJ) $(SRC:.c=.d)
fclean: clean
$(RM) $(NAME)
re: fclean all
-include $(SRC:.c=.d)
.PHONY: all clean fclean re libunit

View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:41:49 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int libunit_launcher(void)
{
t_unit_test *testlist;
size_t res;
testlist = NULL;
load_test(&testlist, "successful", &test_ok, 0);
load_test(&testlist, "unsuccessful", &test_ko, 0);
load_test(&testlist, "sigsegv", &test_sigsegv, 0);
load_test(&testlist, "sigbus", &test_sigbus, 0);
load_test(&testlist, "sigkill", &test_sigkill, 0);
load_test(&testlist, "sigabrt", &test_sigabrt, 0);
load_test(&testlist, "sigfpe", &test_sigfpe, 0);
load_test(&testlist, "sigpipe", &test_sigpipe, 0);
load_test(&testlist, "timeout", &test_timeout, 1);
res = launch_tests(testlist, "libunit");
clear_tests(&testlist);
return (res);
}

16
tests/libunit/01_ok.c Normal file
View File

@@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_ok.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:36:02 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
int test_ok(void)
{
return (0);
}

16
tests/libunit/02_ko.c Normal file
View File

@@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_ko.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:36:07 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
int test_ko(void)
{
return (1);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 03_sigsegv.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:36:33 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../tests.h"
int test_sigsegv(void)
{
return (ft_atoi(NULL) == 0);
return (1);
}

25
tests/libunit/04_sigbus.c Normal file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 04_sigbus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 15:22:52 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int test_sigbus(void)
{
char *cptr;
int *iptr;
__asm__("pushf\norl $0x40000,(%rsp)\npopf");
cptr = malloc(sizeof(int) + 1);
iptr = (int *)++cptr;
*iptr = 42;
return (1);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 05_sigkill.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:38:20 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigkill(void)
{
raise(SIGKILL);
return (1);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 06_sigabrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:38:37 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigabrt(void)
{
raise(SIGABRT);
return (1);
}

19
tests/libunit/07_sigfpe.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 07_sigfpe.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:39:11 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigfpe(void)
{
raise(SIGFPE);
return (1);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 08_sigpipe.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:39:33 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigpipe(void)
{
raise(SIGPIPE);
return (1);
}

View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 09_timeout.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:40:07 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
int test_timeout(void)
{
while (1)
{
}
return (1);
}

18
tests/main.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 18:53:13 by elagouch #+# #+# */
/* Updated: 2026/01/24 18:53:14 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests.h"
int main(void)
{
libunit_launcher();
}

32
tests/tests.h Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */
/* Updated: 2026/01/25 16:40:37 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TESTS_H
# define TESTS_H
# include "libunit.h"
// LAUNCHERS
int libunit_launcher(void);
// libunit
int test_ok(void);
int test_ko(void);
int test_sigsegv(void);
int test_sigbus(void);
int test_sigkill(void);
int test_sigabrt(void);
int test_sigfpe(void);
int test_sigpipe(void);
int test_timeout(void);
#endif // !TESTS_H