added bgoulard lib + made lib sources in their own directory in build/ for readability
This commit is contained in:
parent
83cc8419a0
commit
0a390934d6
457 changed files with 21807 additions and 61 deletions
31
libft_personal/tests/ft_string/ft_char/ft_char_tests.c
Normal file
31
libft_personal/tests/ft_string/ft_char/ft_char_tests.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_char_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 14:31:03 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:37:50 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/char_tests.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
int char_tests(void)
|
||||
{
|
||||
int i;
|
||||
const t_test tests[] = {
|
||||
{"isalnum", test_ft_isalnum}, {"isalpha", test_ft_isalpha},
|
||||
{"isascii", test_ft_isascii}, {"isdigit", test_ft_isdigit},
|
||||
{"isprint", test_ft_isprint}, {"tolower", test_ft_tolower},
|
||||
{"toupper", test_ft_toupper}, {"isalnum", test_ft_isalnum},
|
||||
{"putchar", test_ft_putchar}, {"ishexdigit", test_ft_ishexdigit},
|
||||
{"isoctdigit", test_ft_isoctdigit}, {"isspace", test_ft_isspace},
|
||||
{NULL, NULL}};
|
||||
|
||||
i = 0;
|
||||
run_test(tests, &i);
|
||||
return (i);
|
||||
}
|
||||
28
libft_personal/tests/ft_string/ft_char/tests_isalnum.c
Normal file
28
libft_personal/tests/ft_string/ft_char/tests_isalnum.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:55:54 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:11:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isalnum(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isalnum(i) != ((i >= '0' && i <= '9') || (i >= 'a' && i <= 'z')
|
||||
|| (i >= 'A' && i <= 'Z')))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft_personal/tests/ft_string/ft_char/tests_isalpha.c
Normal file
27
libft_personal/tests/ft_string/ft_char/tests_isalpha.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:56:07 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 15:56:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isalpha(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isalpha(i) != ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z')))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft_personal/tests/ft_string/ft_char/tests_isascii.c
Normal file
27
libft_personal/tests/ft_string/ft_char/tests_isascii.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:56:46 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:30:15 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isascii(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isascii(i) != (i >= 0 && i <= 127))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft_personal/tests/ft_string/ft_char/tests_isdigit.c
Normal file
27
libft_personal/tests/ft_string/ft_char/tests_isdigit.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:57:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 15:57:55 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isdigit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isdigit(i) != (i >= '0' && i <= '9'))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_char/tests_ishexdigit.c
Normal file
35
libft_personal/tests/ft_string/ft_char/tests_ishexdigit.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_ishexdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:25:47 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:26:01 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_ishexdigit(int c)
|
||||
{
|
||||
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')
|
||||
|| (c >= 'A' && c <= 'F'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_ishexdigit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_ishexdigit(i) != local_ishexdigit(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
34
libft_personal/tests/ft_string/ft_char/tests_isoctdigit.c
Normal file
34
libft_personal/tests/ft_string/ft_char/tests_isoctdigit.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isoctdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:26:13 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:26:23 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_isoctdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '7')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_isoctdigit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isoctdigit(i) != local_isoctdigit(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft_personal/tests/ft_string/ft_char/tests_isprint.c
Normal file
27
libft_personal/tests/ft_string/ft_char/tests_isprint.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:57:59 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 15:58:04 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
int test_ft_isprint(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isprint(i) != (i >= 32 && i <= 126))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_char/tests_isspace.c
Normal file
35
libft_personal/tests/ft_string/ft_char/tests_isspace.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_char_isspace.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:32:37 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 21:25:51 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_isspace(int c)
|
||||
{
|
||||
if (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t'
|
||||
|| c == '\v')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_ft_isspace(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_isspace(i) != local_isspace(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
46
libft_personal/tests/ft_string/ft_char/tests_puchar.c
Normal file
46
libft_personal/tests/ft_string/ft_char/tests_puchar.c
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_puchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:01:41 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:18:25 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
#include "tests/tests.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int test_ft_putchar(void)
|
||||
{
|
||||
const char *file;
|
||||
char buf[256];
|
||||
char c;
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
file = "ft_putchar";
|
||||
c = 0;
|
||||
fd = open_test_file((char **)&file);
|
||||
if (fd < 0)
|
||||
return (1);
|
||||
while ((unsigned char)c < 255)
|
||||
ft_putchar_fd(c++, fd);
|
||||
close(fd);
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return (2);
|
||||
ret = read(fd, buf, 256);
|
||||
if (ret != 255)
|
||||
return (3);
|
||||
buf[255] = 0;
|
||||
while (ret--)
|
||||
if (buf[ret] != --c)
|
||||
return (4);
|
||||
return (destroy_test_file(fd, (char *)file), free((char *)file), 0);
|
||||
}
|
||||
34
libft_personal/tests/ft_string/ft_char/tests_tolower.c
Normal file
34
libft_personal/tests/ft_string/ft_char/tests_tolower.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 15:59:59 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:00:44 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c + 32);
|
||||
return (c);
|
||||
}
|
||||
|
||||
int test_ft_tolower(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_tolower(i) != local_tolower(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
34
libft_personal/tests/ft_string/ft_char/tests_toupper.c
Normal file
34
libft_personal/tests/ft_string/ft_char/tests_toupper.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/23 16:01:14 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/23 16:18:41 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_char.h"
|
||||
|
||||
static int local_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
return (c);
|
||||
}
|
||||
|
||||
int test_ft_toupper(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 256)
|
||||
{
|
||||
if (ft_toupper(i) != local_toupper(i))
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_mem/mem_tests.c
Normal file
32
libft_personal/tests/ft_string/ft_mem/mem_tests.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mem_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/30 13:39:27 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 20:54:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/tests.h"
|
||||
#include "tests/str__mem_tests.h"
|
||||
|
||||
int mem_tests(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test tests[] = {
|
||||
{"apply_2d", test_apply_2d}, {"free_2d", test_free_2d},
|
||||
{"len_2d", test_len_2d}, {"fd_to_buff", test_fd_to_buff},
|
||||
{"bzero", test_bzero}, {"calloc", test_calloc}, {"realloc", test_realloc},
|
||||
{"free", test_free}, {"memchr", test_memchr}, {"memcmp", test_memcmp},
|
||||
{"memcpy", test_memcpy}, {"memmap", test_memmap}, {"memmove", test_memmove},
|
||||
{"memset", test_memset}, {"swap", test_swap}, {"qsort", test_qsort},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
collect = 0;
|
||||
run_test(tests, &collect);
|
||||
return (collect);
|
||||
}
|
||||
41
libft_personal/tests/ft_string/ft_mem/tests_apply_2d.c
Normal file
41
libft_personal/tests/ft_string/ft_mem/tests_apply_2d.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_apply_2d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 16:05:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:59:40 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
static void to_a(void *ptr)
|
||||
{
|
||||
char *sptr;
|
||||
|
||||
sptr = (char *)ptr;
|
||||
while (*sptr)
|
||||
{
|
||||
*sptr = 'a';
|
||||
sptr++;
|
||||
}
|
||||
}
|
||||
|
||||
int test_apply_2d(void)
|
||||
{
|
||||
char *arr2d[4];
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < 3)
|
||||
arr2d[i++] = ft_strdup("Hello World");
|
||||
arr2d[i] = NULL;
|
||||
ft_apply_2d((void **)arr2d, to_a);
|
||||
if (ft_strcmp(arr2d[0], "aaaaaaaaaaa") != 0 || ft_strcmp(arr2d[1],
|
||||
"aaaaaaaaaaa") != 0 || ft_strcmp(arr2d[2], "aaaaaaaaaaa") != 0)
|
||||
return (1);
|
||||
return (ft_apply_2d((void **)arr2d, free), 0);
|
||||
}
|
||||
25
libft_personal/tests/ft_string/ft_mem/tests_bzero.c
Normal file
25
libft_personal/tests/ft_string/ft_mem/tests_bzero.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:24:17 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 14:37:09 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_bzero(void)
|
||||
{
|
||||
char str[10];
|
||||
const char str2[10] = {0};
|
||||
|
||||
ft_strlcpy(str, "123456789", 10);
|
||||
ft_bzero(str, 10);
|
||||
if (ft_memcmp(str, str2, 10) != 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
33
libft_personal/tests/ft_string/ft_mem/tests_calloc.c
Normal file
33
libft_personal/tests/ft_string/ft_mem/tests_calloc.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:23:35 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/25 21:40:19 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// str[x] = 'a' is to test that we can write in the memory we asked for
|
||||
int test_calloc(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = ft_calloc(10, sizeof(char));
|
||||
str[9] = 'a';
|
||||
free(str);
|
||||
str = ft_calloc(10, sizeof(char *));
|
||||
str[9 * sizeof(char *)] = 'a';
|
||||
free(str);
|
||||
str = ft_calloc(0, sizeof(char));
|
||||
free(str);
|
||||
str = ft_calloc(SIZE_MAX, SIZE_MAX);
|
||||
if (str)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
71
libft_personal/tests/ft_string/ft_mem/tests_fd_to_buff.c
Normal file
71
libft_personal/tests/ft_string/ft_mem/tests_fd_to_buff.c
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_fd_to_buff.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 16:15:20 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/26 19:34:37 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
static int base_case(void)
|
||||
{
|
||||
char buff[100];
|
||||
char *ret;
|
||||
int fd;
|
||||
|
||||
ft_bzero(buff, 100);
|
||||
ft_strlcat(buff, "Hello World\n\n\n\n\tv\vjkldqskjfsldfjsmldfkj\n", 100);
|
||||
fd = open(TESTS_FPREFIX "test_fd_to_buff.txt", O_RDWR | O_CREAT, 0644);
|
||||
if (fd < 0)
|
||||
return (1);
|
||||
write(fd, buff, ft_strlen(buff));
|
||||
close(fd);
|
||||
fd = open(TESTS_FPREFIX "test_fd_to_buff.txt", O_RDONLY | O_CREAT);
|
||||
if (fd < 0)
|
||||
return (2);
|
||||
ret = ft_fd_to_buff(fd);
|
||||
if (ft_strcmp(ret, buff) != 0)
|
||||
return (3);
|
||||
destroy_test_file(fd, TESTS_FPREFIX "test_fd_to_buff.txt");
|
||||
return (free(ret), 0);
|
||||
}
|
||||
|
||||
static int error_case(void)
|
||||
{
|
||||
char *ret;
|
||||
int bad_fd;
|
||||
|
||||
bad_fd = -1;
|
||||
ret = ft_fd_to_buff(bad_fd);
|
||||
if (ret)
|
||||
return (1);
|
||||
bad_fd = open(TESTS_FPREFIX "test_fd_to_buff.txt", O_CREAT, 0004);
|
||||
if (bad_fd < 0)
|
||||
return (2);
|
||||
close(bad_fd);
|
||||
bad_fd = open(TESTS_FPREFIX "test_fd_to_buff.txt", O_RDONLY);
|
||||
ret = ft_fd_to_buff(bad_fd);
|
||||
if (ret)
|
||||
return (3);
|
||||
destroy_test_file(bad_fd, TESTS_FPREFIX "test_fd_to_buff.txt");
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_fd_to_buff(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = base_case();
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = error_case();
|
||||
if (ret != 0)
|
||||
return (ret + 10);
|
||||
return (0);
|
||||
}
|
||||
26
libft_personal/tests/ft_string/ft_mem/tests_free.c
Normal file
26
libft_personal/tests/ft_string/ft_mem/tests_free.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_free.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:22:59 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/08/21 21:49:05 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_free(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = ft_calloc(10, sizeof(char));
|
||||
ft_free((void **)&str);
|
||||
if (str)
|
||||
return (1);
|
||||
ft_free((void **)&str);
|
||||
ft_free((void **) NULL);
|
||||
return (0);
|
||||
}
|
||||
24
libft_personal/tests/ft_string/ft_mem/tests_free_2d.c
Normal file
24
libft_personal/tests/ft_string/ft_mem/tests_free_2d.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_free_2d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 23:42:53 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/28 23:55:41 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
// we assume that free_2d is working,
|
||||
// checking if memory is freed properly is not possible in this context
|
||||
int test_free_2d(void)
|
||||
{
|
||||
char **tab;
|
||||
|
||||
tab = ft_split("Hello World", ' ');
|
||||
ft_free_2d((void **)tab);
|
||||
return (0);
|
||||
}
|
||||
26
libft_personal/tests/ft_string/ft_mem/tests_len_2d.c
Normal file
26
libft_personal/tests/ft_string/ft_mem/tests_len_2d.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_len_2d.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 00:11:07 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/29 00:15:46 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_len_2d(void)
|
||||
{
|
||||
char *arr2d[4];
|
||||
|
||||
arr2d[0] = "Hello";
|
||||
arr2d[1] = "World";
|
||||
arr2d[2] = "!";
|
||||
arr2d[3] = NULL;
|
||||
if (ft_len_2d((const void *const *)arr2d) != 3)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_mem/tests_memchr.c
Normal file
32
libft_personal/tests/ft_string/ft_mem/tests_memchr.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:22:42 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:18:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_memchr(void)
|
||||
{
|
||||
char str[10];
|
||||
|
||||
ft_strlcpy(str, "1234567", 10);
|
||||
ft_strlcat(str, "890", 10);
|
||||
if (ft_memchr(str, '8', 10) != &str[7])
|
||||
return (1);
|
||||
if (ft_memchr(str, '9', 10) != &str[8])
|
||||
return (2);
|
||||
if (ft_memchr(str, 'z', 10))
|
||||
return (3);
|
||||
if (ft_memchr(str, '7', 10) != &str[6])
|
||||
return (4);
|
||||
if (ft_memchr(str, '7', 0))
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_mem/tests_memcmp.c
Normal file
35
libft_personal/tests/ft_string/ft_mem/tests_memcmp.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:22:12 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 00:46:20 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_memcmp(void)
|
||||
{
|
||||
const char str[] = "1234567\0009";
|
||||
const char str2[] = "1234567\0009";
|
||||
const char str3[] = "1234567\000a";
|
||||
const char str4[] = "1234567\0009";
|
||||
|
||||
if (ft_memcmp(str, str2, 10) != 0)
|
||||
return (1);
|
||||
if (ft_memcmp(str, str3, 10) >= 0)
|
||||
return (2);
|
||||
if (ft_memcmp(str3, str, 10) <= 0)
|
||||
return (3);
|
||||
if (ft_memcmp(str, str2, 0) != 0)
|
||||
return (4);
|
||||
if (ft_memcmp(str, str4, 10) != 0)
|
||||
return (5);
|
||||
if (ft_memcmp(str, str, 999) != 0)
|
||||
return (6);
|
||||
return (0);
|
||||
}
|
||||
31
libft_personal/tests/ft_string/ft_mem/tests_memcpy.c
Normal file
31
libft_personal/tests/ft_string/ft_mem/tests_memcpy.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:22:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 00:49:34 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
// last ft_memcpy is a test to check that we do nothing on
|
||||
// dst if src and dst are the same otherwise it will segfault
|
||||
int test_memcpy(void)
|
||||
{
|
||||
char str[10];
|
||||
const char str3[] = "1234567\0009";
|
||||
|
||||
ft_strlcpy(str, "123456789", 10);
|
||||
ft_memcpy(str, "abc", 3);
|
||||
if (ft_memcmp(str, "abc456789", 10) != 0)
|
||||
return (1);
|
||||
ft_memcpy(str, str3, 10);
|
||||
if (ft_memcmp(str, str3, 10) != 0)
|
||||
return (2);
|
||||
ft_memcpy(str, str, 999);
|
||||
return (0);
|
||||
}
|
||||
40
libft_personal/tests/ft_string/ft_mem/tests_memmap.c
Normal file
40
libft_personal/tests/ft_string/ft_mem/tests_memmap.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_memmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:21:39 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 00:53:07 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_defs.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_memmap(void)
|
||||
{
|
||||
const char *tb[3] = {"Hello", "World", "!"};
|
||||
char **str2;
|
||||
|
||||
str2 = (char **) ft_memmap((void *)tb, sizeof(tb) / sizeof(tb[0]),
|
||||
(t_data_tr)ft_strdup);
|
||||
if (ft_strcmp(str2[0], "Hello") != 0)
|
||||
return (1);
|
||||
if (ft_strcmp(str2[1], "World") != 0)
|
||||
return (1);
|
||||
if (ft_strcmp(str2[2], "!") != 0)
|
||||
return (1);
|
||||
ft_free_2d((void **)str2);
|
||||
str2 = (char **) ft_memmap(NULL, 0, (t_data_tr)ft_strdup);
|
||||
if (str2)
|
||||
return (2);
|
||||
str2 = (char **) ft_memmap((void *)tb, 0, (t_data_tr)ft_strdup);
|
||||
if (str2)
|
||||
return (3);
|
||||
str2 = (char **) ft_memmap((void *)tb, sizeof(tb) / sizeof(tb[0]), NULL);
|
||||
if (str2)
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
37
libft_personal/tests/ft_string/ft_mem/tests_memmove.c
Normal file
37
libft_personal/tests/ft_string/ft_mem/tests_memmove.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:21:39 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/26 19:27:55 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
// last ft_memmove is a test to check that we do nothing on
|
||||
// dst if src and dst are the same otherwise it will segfault
|
||||
int test_memmove(void)
|
||||
{
|
||||
char str[10];
|
||||
const char str3[] = "1234567a9";
|
||||
|
||||
ft_strlcpy(str, "123456789", 10);
|
||||
ft_memmove(str, "abc", 3);
|
||||
if (ft_memcmp(str, "abc456789", 10) != 0)
|
||||
return (1);
|
||||
ft_memmove(str, str3, 10);
|
||||
if (ft_memcmp(str, str3, 10) != 0)
|
||||
return (2);
|
||||
ft_memmove(str, str + 2, 5);
|
||||
if (ft_memcmp(str, "3456767a9", 10) != 0)
|
||||
return (3);
|
||||
ft_memmove(str + 2, str, 5);
|
||||
if (ft_memcmp(str, "3434567a9", 10) != 0)
|
||||
return (4);
|
||||
ft_memmove(str, str, 999);
|
||||
return (0);
|
||||
}
|
||||
37
libft_personal/tests/ft_string/ft_mem/tests_memset.c
Normal file
37
libft_personal/tests/ft_string/ft_mem/tests_memset.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:21:24 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:01:56 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
/*
|
||||
// ignore warning for memset args
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wmemset-transposed-args"
|
||||
*/
|
||||
int test_memset(void)
|
||||
{
|
||||
char str[10];
|
||||
char str2[10];
|
||||
|
||||
ft_strlcpy(str, "123456789", 10);
|
||||
ft_strlcpy(str2, "123456789", 10);
|
||||
ft_memset(str, 'a', 10);
|
||||
if (ft_memcmp(str, "aaaaaaaaaa", 10) != 0)
|
||||
return (1);
|
||||
ft_memset(str, 'b', 0);
|
||||
if (ft_memcmp(str, "aaaaaaaaaa", 10) != 0)
|
||||
return (2);
|
||||
ft_memset(str, 'c', 5);
|
||||
if (ft_memcmp(str, "cccccaaaaa", 10) != 0)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
31
libft_personal/tests/ft_string/ft_mem/tests_qsort.c
Normal file
31
libft_personal/tests/ft_string/ft_mem/tests_qsort.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_qsort.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:20:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/25 12:20:11 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// non stable
|
||||
// int tab[10] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 9};
|
||||
// int tab2[10] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 9};
|
||||
// int tab3[10] = {1, 256, 3, 4, -6, 7, 81, 10, 9};
|
||||
// int tab4[10] = {1, 256, 3, 4, -6, 7, 81, 10, 9};
|
||||
|
||||
// ft_qsort(tab, 10, sizeof(int), cmp_int);
|
||||
// qsort(tab2, 10, sizeof(int), cmp_int);
|
||||
// if (memcmp(tab, tab2, 10) != 0)
|
||||
// return (1);
|
||||
|
||||
// ft_qsort(tab3, 10, sizeof(int), cmp_int);
|
||||
// qsort(tab4, 10, sizeof(int), cmp_int);
|
||||
// if (memcmp(tab3, tab4, 10) != 0)
|
||||
// return (2);
|
||||
int test_qsort(void)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
31
libft_personal/tests/ft_string/ft_mem/tests_realloc.c
Normal file
31
libft_personal/tests/ft_string/ft_mem/tests_realloc.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_realloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:21:02 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/26 19:27:29 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_realloc(void)
|
||||
{
|
||||
char *str;
|
||||
char *str_ret;
|
||||
|
||||
str = ft_calloc(15, sizeof(char));
|
||||
ft_strlcpy(str, "Hello world", 15);
|
||||
str = ft_realloc(str, 25, 15);
|
||||
ft_strlcat(str, " this is zod!", 25);
|
||||
if (ft_strcmp(str, "Hello world this is zod!") != 0)
|
||||
return (1);
|
||||
str_ret = ft_realloc(str, 10, 10);
|
||||
if (str != str_ret)
|
||||
return (2);
|
||||
free(str);
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_mem/tests_swap.c
Normal file
32
libft_personal/tests/ft_string/ft_mem/tests_swap.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 12:20:29 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/25 15:13:47 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
/*
|
||||
// ignore warning for memset args
|
||||
#pragma clang diagnostic pop
|
||||
*/
|
||||
|
||||
int test_swap(void)
|
||||
{
|
||||
const int pair_og[2] = {1, 2};
|
||||
const int *pair[2];
|
||||
const int *pair2[2] = {&pair_og[1], &pair_og[0]};
|
||||
|
||||
pair[0] = &pair_og[0];
|
||||
pair[1] = &pair_og[1];
|
||||
ft_swap((void **)&pair[0], (void **)&pair[1]);
|
||||
if (pair[0] != pair2[0] || pair[1] != pair2[1])
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
53
libft_personal/tests/ft_string/ft_str/str_tests.c
Normal file
53
libft_personal/tests/ft_string/ft_str/str_tests.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* str_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/30 13:39:29 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 11:23:03 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/str__str_tests.h"
|
||||
#include "tests/tests.h"
|
||||
#include <stddef.h>
|
||||
|
||||
static const t_test *load_tests01(void)
|
||||
{
|
||||
static t_test tb[] = {{"putstr", test_putstr}, {"putendl", test_putendl},
|
||||
{"putnbr", test_putnbr}, {"itoa", test_itoa}, {"utoa", test_utoa}, \
|
||||
{"itoa_base", test_itoa_base}, {"atoi", test_atoi}, {"atoi_base", \
|
||||
test_atoi_base}, {"tok", test_strtok}, {"split", test_split},
|
||||
{"splits", tests_splits}, {"chr", test_strchr}, {"dup", test_strdup}, \
|
||||
{"iteri", test_striteri}, {"join", test_strjoin}, {"lcat", test_strlcat}, \
|
||||
{"lcpy", test_strlcpy}, {"len", test_strlen}, {"mapi", test_strmapi}, \
|
||||
{"cmp", test_strcmp}, {"ncmp", test_strncmp}, {"ndup", test_strndup}, \
|
||||
{"nstr", test_strnstr}, {"rchr", test_strrchr}, {"trim", test_strtrim}, \
|
||||
{"substr", test_substr}, {"replace", test_str_replace}, \
|
||||
{"replace_chr", test_str_replace_chr}, {"shift_args", test_shift_args}, \
|
||||
{"gnl", test_gnl}, {"atof", test_atof}, {"isalpha", test_str_isalpha}, \
|
||||
{"isbool", test_str_isbool}, {"alnum", test_str_isalnum}, \
|
||||
{"isdigit", test_str_isdigit}, {"isdouble", test_str_isdouble}, \
|
||||
{"ishex", test_str_ishex}, {"islong", test_str_islong}, \
|
||||
{"isnum", test_str_isnum}, {"isoct", test_str_isoct}, \
|
||||
{"isint", test_str_isint}, {"isfloat", test_str_isfloat}, \
|
||||
{"isvalid", test_str_isvalid}, {"clen", test_strclen}, \
|
||||
{"cnb", test_strcnb}, {"cspn", test_strcspn}, \
|
||||
{"end_with", test_strend_with}, {"start_with", test_strstart_with}, \
|
||||
{"spn", test_strspn}, {"append_c", test_strappend_c},
|
||||
{NULL, NULL}};
|
||||
|
||||
return (tb);
|
||||
}
|
||||
|
||||
int str_tests(void)
|
||||
{
|
||||
int collect;
|
||||
const t_test *tests = load_tests01();
|
||||
|
||||
collect = 0;
|
||||
run_test(tests, &collect);
|
||||
return (collect);
|
||||
}
|
||||
39
libft_personal/tests/ft_string/ft_str/test_atof.c
Normal file
39
libft_personal/tests/ft_string/ft_str/test_atof.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_atof.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 16:08:52 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 16:00:09 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_atof(void)
|
||||
{
|
||||
double res;
|
||||
size_t i;
|
||||
const float marge = 0.00001;
|
||||
const double t_cases[] = {
|
||||
1.13, 3.14, 0.0, 0.1, 0.0001, -0.2, -0.3, 0.3, 1200, 0,
|
||||
3.15, -3.15, 0.15
|
||||
};
|
||||
const char *t_str[] = {
|
||||
"1.13", "3.14", "0.0", "0.1", "0.0001",
|
||||
"-0.2", "-.3", ".3", "1200", "0", " +3.15",
|
||||
" -3.15", " .15"
|
||||
};
|
||||
|
||||
i = 0;
|
||||
while (i < sizeof(t_cases) / sizeof(t_cases[0]))
|
||||
{
|
||||
res = ft_atof(t_str[i]);
|
||||
if (res < t_cases[i] - marge || res > t_cases[i] + marge)
|
||||
return (i + 1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
42
libft_personal/tests/ft_string/ft_str/test_atoi.c
Normal file
42
libft_personal/tests/ft_string/ft_str/test_atoi.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/26 11:45:29 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_atoi(void)
|
||||
{
|
||||
size_t i;
|
||||
const int t_cases[] = {
|
||||
0, 1, 9, 10, 99, 100, 999, 1000, 9999, 10000, -1, -9,
|
||||
-10, -99, -100, -999, -1000, -9999, -10000
|
||||
};
|
||||
const char *t_str[] = {
|
||||
"0", "1", "9", "10", "99", "100", "999", "1000",
|
||||
"9999", "10000", "-1", "-9", "-10", "-99", "-100", "-999", "-1000",
|
||||
"-9999", "-10000"
|
||||
};
|
||||
|
||||
i = 0;
|
||||
while (i < sizeof(t_cases) / sizeof(t_cases[0]))
|
||||
{
|
||||
if (ft_atoi(t_str[i]) != t_cases[i])
|
||||
return (i + 1);
|
||||
i++;
|
||||
}
|
||||
if (ft_atoi(" --99") != 99 || ft_atoi(" -0") != 0 || \
|
||||
ft_atoi(" -++--1") != -1)
|
||||
return (30);
|
||||
if (ft_atoi("toto") != 0 || ft_atoi("-toto") != 0 || ft_atoi("toto-") \
|
||||
!= 0 || ft_atoi("a") != 0 || ft_atoi("01234\t56789") != 1234)
|
||||
return (31);
|
||||
return (0);
|
||||
}
|
||||
99
libft_personal/tests/ft_string/ft_str/test_atoi_base.c
Normal file
99
libft_personal/tests/ft_string/ft_str/test_atoi_base.c
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_atoi_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/26 16:42:38 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
static int test_base_resps(const char *base, const int *expected_results,
|
||||
const char **inputs)
|
||||
{
|
||||
int i;
|
||||
int res;
|
||||
|
||||
i = 0;
|
||||
while (inputs[i])
|
||||
{
|
||||
res = ft_atoi_base(inputs[i], base);
|
||||
if (res != expected_results[i])
|
||||
return (i + 1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test_spaces(void)
|
||||
{
|
||||
if (ft_atoi_base(" 0", "0123456789") != 0)
|
||||
return (1);
|
||||
if (ft_atoi_base(" 1", "0123456789") != 1)
|
||||
return (2);
|
||||
if (ft_atoi_base(" 9", "0123456789") != 9)
|
||||
return (3);
|
||||
if (ft_atoi_base(" 10", "0123456789") != 10)
|
||||
return (4);
|
||||
if (ft_atoi_base(" 99", "0123456789") != 99)
|
||||
return (5);
|
||||
if (ft_atoi_base(" -99", "0123456789") != -99)
|
||||
return (6);
|
||||
if (ft_atoi_base(" -0", "0123456789") != 0)
|
||||
return (7);
|
||||
if (ft_atoi_base(" -1", "0123456789") != -1)
|
||||
return (8);
|
||||
if (ft_atoi_base(" -10", "0123456789") != -10)
|
||||
return (9);
|
||||
if (ft_atoi_base(" -99", "0123456789") != -99)
|
||||
return (10);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test_multi_sign(void)
|
||||
{
|
||||
if (ft_atoi_base(" --99", "0123456789") != 99)
|
||||
return (1);
|
||||
if (ft_atoi_base(" -0", "0123456789") != 0)
|
||||
return (2);
|
||||
if (ft_atoi_base(" -++--1", "0123456789") != -1)
|
||||
return (3);
|
||||
if (ft_atoi_base(" -+--10", "0123456789") != -10)
|
||||
return (4);
|
||||
if (ft_atoi_base(" -+--99", "0123456789") != -99)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_atoi_base(void)
|
||||
{
|
||||
const char *bases[] = {"0123456789", "01", "0123456789abcdef"};
|
||||
const int expected_results[][11] = {
|
||||
{0, 1, 9, 10, 99, 0, -1, -9, -10, -99},
|
||||
{0, 1, 2, 3, 4, 0, -1, -2, -3, -4},
|
||||
{0, 10, 15, 16, 153, 0, -10, -15, -16, -153}
|
||||
};
|
||||
const char *strs[][12] = {
|
||||
{"0", "1", "9", "10", "99", "0", "-1", "-9", "-10", "-99", NULL},
|
||||
{"0", "1", "10", "11", "100", "0", "-1", "-10", "-11", "-100", NULL},
|
||||
{"0", "a", "f", "10", "99", "0", "-a", "-f", "-10", "-99", NULL}
|
||||
};
|
||||
|
||||
if (test_base_resps(bases[0], expected_results[0], strs[0]) || \
|
||||
test_base_resps(bases[1], expected_results[1], strs[1]) || \
|
||||
test_base_resps(bases[2], expected_results[2], strs[2]))
|
||||
return (1);
|
||||
if (ft_atoi_base("23", "011") || ft_atoi_base("23", "0") || \
|
||||
ft_atoi_base("23", "1") || ft_atoi_base("23", "0123456789-") || \
|
||||
ft_atoi_base("23", "0123456789+"))
|
||||
return (2);
|
||||
if (test_spaces())
|
||||
return (3);
|
||||
if (test_multi_sign())
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
75
libft_personal/tests/ft_string/ft_str/test_gnl.c
Normal file
75
libft_personal/tests/ft_string/ft_str/test_gnl.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_gnl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 14:26:14 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "tests/tests.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
static int write_lines(const char **lines, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
int fd;
|
||||
|
||||
fd = open(TESTS_FPREFIX "gnl.txt", O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0)
|
||||
return (-1);
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
write(fd, lines[i], ft_strlen(lines[i]));
|
||||
i++;
|
||||
}
|
||||
close(fd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static const char **return_lines(size_t *n)
|
||||
{
|
||||
static const char *test_lines[] = {
|
||||
"Hello World!\n",
|
||||
"This is Zod!\n",
|
||||
"Zod shall henceforth be the new earth emperor. Prepare yourself "
|
||||
"earthilings to the terrible rule of zod the space warrior and self "
|
||||
"proclaimed emperor of the gallaxy. this is a really long line btw... "
|
||||
"i sure hope gnl will parse it............................\n",
|
||||
"Goodbye World!\n",
|
||||
};
|
||||
|
||||
*n = sizeof(test_lines) / sizeof(test_lines[0]);
|
||||
return (test_lines);
|
||||
}
|
||||
|
||||
int test_gnl(void)
|
||||
{
|
||||
int fd;
|
||||
char *line;
|
||||
size_t i;
|
||||
size_t lines_count;
|
||||
const char **test_lines = return_lines(&lines_count);
|
||||
|
||||
line = NULL;
|
||||
if (write_lines(test_lines, lines_count) < 0)
|
||||
return (1);
|
||||
fd = open(TESTS_FPREFIX "gnl.txt", O_RDONLY);
|
||||
i = 0;
|
||||
while (i < lines_count)
|
||||
{
|
||||
line = get_next_line(fd);
|
||||
if (ft_strcmp(line, test_lines[i++]) != 0)
|
||||
return (i + 1);
|
||||
free(line);
|
||||
}
|
||||
line = get_next_line(fd);
|
||||
if (line)
|
||||
return (2);
|
||||
return (free(line), destroy_test_file(fd, TESTS_FPREFIX "gnl.txt"), 0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_str/test_itoa.c
Normal file
32
libft_personal/tests/ft_string/ft_str/test_itoa.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 14:26:38 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_itoa(void)
|
||||
{
|
||||
char *res;
|
||||
size_t i;
|
||||
const int t_cases[] = {0, 123, -456, 7890, -12345};
|
||||
const char *expected_results[] = {"0", "123", "-456", "7890", "-12345"};
|
||||
|
||||
i = 0;
|
||||
while (i < sizeof(t_cases) / sizeof(t_cases[0]))
|
||||
{
|
||||
res = ft_itoa(t_cases[i]);
|
||||
if (ft_strcmp(res, expected_results[i++]) != 0)
|
||||
return (i);
|
||||
free(res);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
67
libft_personal/tests/ft_string/ft_str/test_itoa_base.c
Normal file
67
libft_personal/tests/ft_string/ft_str/test_itoa_base.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_itoa_base.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/23 18:24:21 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
#define MAGIC 42
|
||||
|
||||
int eval_base(int *t_cases, const char *bases, const char *expected_results[])
|
||||
{
|
||||
char *res;
|
||||
size_t j;
|
||||
|
||||
j = 0;
|
||||
while (t_cases[j] != MAGIC)
|
||||
{
|
||||
res = ft_itoa_base(t_cases[j], bases);
|
||||
if (ft_strcmp(res, expected_results[j]) != 0)
|
||||
return (free(res), j + 1);
|
||||
free(res);
|
||||
j++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int check_base_error(void)
|
||||
{
|
||||
if (ft_itoa_base(0, "0") || ft_itoa_base(0, "010") || \
|
||||
ft_itoa_base(0, "0123456789+") || ft_itoa_base(0, "0123456789a-") \
|
||||
|| ft_itoa_base(0, "0123456789a1") || ft_itoa_base(0, "0123456789a ") \
|
||||
|| ft_itoa_base(0, "0123456789\t"))
|
||||
return (15);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_itoa_base(void)
|
||||
{
|
||||
size_t j;
|
||||
const int t_cases[] = {0, 123, -456, 7890, -12345, MAGIC};
|
||||
const char *bases[] = {"0123456789abcdef", "0123456789", "01",
|
||||
"0123456789ABCDEF"};
|
||||
const char *expected_results[sizeof(bases)
|
||||
/ sizeof(bases[0])][sizeof(t_cases) / sizeof(t_cases[0])] = {{"0", "7b",
|
||||
"-1c8", "1ed2", "-3039"}, {"0", "123", "-456", "7890", "-12345"}, {"0",
|
||||
"1111011", "-111001000", "1111011010010", "-11000000111001"}, {"0",
|
||||
"7B", "-1C8", "1ED2", "-3039"}};
|
||||
|
||||
j = 0;
|
||||
while (j < sizeof(bases) / sizeof(bases[0]))
|
||||
{
|
||||
if (eval_base((int *)t_cases, bases[j], expected_results[j]) != 0)
|
||||
return (j + 1);
|
||||
j++;
|
||||
}
|
||||
if (check_base_error() != 0)
|
||||
return (j + check_base_error());
|
||||
return (0);
|
||||
}
|
||||
43
libft_personal/tests/ft_string/ft_str/test_putendl.c
Normal file
43
libft_personal/tests/ft_string/ft_str/test_putendl.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_putendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:07:22 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
int test_putendl(void)
|
||||
{
|
||||
const char *str;
|
||||
int fd;
|
||||
char buff[100];
|
||||
int bread;
|
||||
const char file_name[] = TESTS_FPREFIX "putendl.txt";
|
||||
|
||||
str = "Hello World!";
|
||||
fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||
ft_putendl_fd(str, fd);
|
||||
close(fd);
|
||||
fd = open(file_name, O_RDONLY);
|
||||
bread = read(fd, buff, 100);
|
||||
if (bread < 0 || ft_strncmp(buff, str, ft_strlen(str)) != 0
|
||||
|| buff[ft_strlen(str)] != '\n')
|
||||
return (1);
|
||||
destroy_test_file(fd, file_name);
|
||||
fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||
ft_putendl_fd(NULL, fd);
|
||||
close(fd);
|
||||
fd = open(file_name, O_RDONLY);
|
||||
bread = read(fd, buff, 100);
|
||||
if (bread != 0)
|
||||
return (2);
|
||||
destroy_test_file(fd, file_name);
|
||||
return (0);
|
||||
}
|
||||
81
libft_personal/tests/ft_string/ft_str/test_putnbr.c
Normal file
81
libft_personal/tests/ft_string/ft_str/test_putnbr.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/19 21:29:17 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "tests/tests.h"
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int nb_to_file(const int *nbs, size_t size, const char *file_name)
|
||||
{
|
||||
int fd;
|
||||
size_t i;
|
||||
|
||||
fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0)
|
||||
return (-1);
|
||||
i = 0;
|
||||
while (i < size)
|
||||
{
|
||||
ft_putnbr_fd(nbs[i], fd);
|
||||
ft_putstr_fd("\n", fd);
|
||||
i++;
|
||||
}
|
||||
close(fd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int file_cmp(const char *file_name, const char *expected)
|
||||
{
|
||||
int fd;
|
||||
char buff[100];
|
||||
|
||||
fd = open(file_name, O_RDONLY);
|
||||
ft_bzero(buff, sizeof(buff));
|
||||
read(fd, buff, sizeof(buff));
|
||||
if (ft_strncmp(buff, expected, sizeof(buff)))
|
||||
return (1);
|
||||
return (destroy_test_file(fd, file_name), 0);
|
||||
}
|
||||
|
||||
static int test_positives(void)
|
||||
{
|
||||
const int t_cases[] = {0, 1, 9, 10, 99, 100, 999, 1000, 9999, 10000, \
|
||||
INT_MAX};
|
||||
const char *expected = "0\n1\n9\n10\n99\n100\n999\n1000\n9999\n10000\n"
|
||||
"2147483647\n";
|
||||
const char *file_name = TESTS_FPREFIX "putnbr.txt";
|
||||
|
||||
nb_to_file(t_cases, sizeof(t_cases) / sizeof(t_cases[0]), file_name);
|
||||
return (file_cmp(file_name, expected));
|
||||
}
|
||||
|
||||
static int test_negatives(void)
|
||||
{
|
||||
const int nbs[] = {-1, -9, -10, -99, -100, -999, -1000, -9999, -10000, \
|
||||
INT_MIN};
|
||||
const char *exp = "-1\n-9\n-10\n-99\n-100\n-999\n-1000\n-9999\n-10000\n"
|
||||
"-2147483648\n";
|
||||
const char *file_name = TESTS_FPREFIX "putnbr.txt";
|
||||
|
||||
nb_to_file(nbs, sizeof(nbs) / sizeof(nbs[0]), file_name);
|
||||
return (file_cmp(file_name, exp));
|
||||
}
|
||||
|
||||
int test_putnbr(void)
|
||||
{
|
||||
if (test_positives() != 0)
|
||||
return (1);
|
||||
if (test_negatives() != 0)
|
||||
return (2);
|
||||
return (0);
|
||||
}
|
||||
41
libft_personal/tests/ft_string/ft_str/test_putstr.c
Normal file
41
libft_personal/tests/ft_string/ft_str/test_putstr.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:08:01 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
int test_putstr(void)
|
||||
{
|
||||
const char file_name[] = TESTS_FPREFIX "putstr.txt";
|
||||
const char *str = "Hello World!";
|
||||
int fd;
|
||||
char buff[100];
|
||||
int bread;
|
||||
|
||||
fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||
ft_putstr_fd(str, fd);
|
||||
close(fd);
|
||||
fd = open(file_name, O_RDONLY);
|
||||
bread = read(fd, buff, 100);
|
||||
if (bread < 0 || ft_strncmp(buff, str, ft_strlen(str)) != 0)
|
||||
return (1);
|
||||
destroy_test_file(fd, file_name);
|
||||
fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
|
||||
ft_putstr_fd(NULL, fd);
|
||||
close(fd);
|
||||
fd = open(file_name, O_RDONLY);
|
||||
bread = read(fd, buff, 100);
|
||||
if (bread != 0)
|
||||
return (2);
|
||||
destroy_test_file(fd, file_name);
|
||||
return (0);
|
||||
}
|
||||
41
libft_personal/tests/ft_string/ft_str/test_shift_args.c
Normal file
41
libft_personal/tests/ft_string/ft_str/test_shift_args.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_shift_args.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/07/06 17:39:55 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_shift_args(void)
|
||||
{
|
||||
const char **tmp = NULL;
|
||||
const char **test;
|
||||
int fake_argc;
|
||||
const char *ret;
|
||||
const char *fake_args[] = (const char *[]) \
|
||||
{"test", "1", "2", "3", "4", NULL};
|
||||
|
||||
test = fake_args;
|
||||
ret = NULL;
|
||||
fake_argc = 5;
|
||||
ret = ft_shift_args(&test, &fake_argc);
|
||||
if (fake_argc != 4 || ft_strcmp(test[0], "1") != 0 || \
|
||||
ft_strcmp(test[1], "2") != 0 || ft_strcmp(test[2], "3") != 0 || \
|
||||
ft_strcmp(test[3], "4") != 0 || ft_strcmp(ret, "test") != 0)
|
||||
return (1);
|
||||
(ft_shift_args(&test, &fake_argc), ft_shift_args(&test, &fake_argc), \
|
||||
ft_shift_args(&test, &fake_argc), ft_shift_args(&test, &fake_argc));
|
||||
ret = ft_shift_args(&test, &fake_argc);
|
||||
if (fake_argc != 0 || ret)
|
||||
return (2);
|
||||
fake_argc = 4012;
|
||||
if (ft_shift_args(&test, &fake_argc) || ft_shift_args(&tmp, &fake_argc))
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
38
libft_personal/tests/ft_string/ft_str/test_split.c
Normal file
38
libft_personal/tests/ft_string/ft_str/test_split.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:08:58 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_split(void)
|
||||
{
|
||||
const char *str = " Hello World! ";
|
||||
char **res;
|
||||
const char *str2 = "Hello World! ";
|
||||
char **res2;
|
||||
size_t i;
|
||||
|
||||
res = ft_split(str, ' ');
|
||||
res2 = ft_split(str2, ' ');
|
||||
if (ft_strcmp(res[0], "Hello") != 0 || ft_strcmp(res[1], "World!") != 0
|
||||
|| res[2])
|
||||
return (1);
|
||||
if (ft_strcmp(res2[0], "Hello") != 0 || ft_strcmp(res2[1], "World!") != 0
|
||||
|| res2[2])
|
||||
return (2);
|
||||
i = 0;
|
||||
while (res[i])
|
||||
free(res[i++]);
|
||||
i = 0;
|
||||
while (res2[i])
|
||||
free(res2[i++]);
|
||||
return (free(res), free(res2), 0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_str/test_splits.c
Normal file
35
libft_personal/tests/ft_string/ft_str/test_splits.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_splits.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:22:48 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 14:16:23 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stddef.h>
|
||||
|
||||
int tests_splits(void)
|
||||
{
|
||||
const char *str;
|
||||
char **res;
|
||||
size_t i;
|
||||
|
||||
str = "path/to/file:another/path:yet/another/path";
|
||||
res = ft_splits(str, " /:");
|
||||
if (ft_strcmp(res[0], "path") != 0 || ft_strcmp(res[1], "to") != 0 || \
|
||||
ft_strcmp(res[2], "file") != 0 || ft_strcmp(res[3], "another") != 0 || \
|
||||
ft_strcmp(res[4], "path") != 0 || ft_strcmp(res[5], "yet") != 0 || \
|
||||
ft_strcmp(res[6], "another") != 0 || ft_strcmp(res[7], "path") != 0 || \
|
||||
res[8])
|
||||
return (1);
|
||||
i = 0;
|
||||
while (res[i])
|
||||
free(res[i++]);
|
||||
free(res);
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_str/test_str_isalnum.c
Normal file
32
libft_personal/tests/ft_string/ft_str/test_str_isalnum.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:43:00 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isalnum(void)
|
||||
{
|
||||
if (ft_str_isalnum("HelloWorld42") != 1)
|
||||
return (1);
|
||||
if (ft_str_isalnum("Hello World42") != 0)
|
||||
return (2);
|
||||
if (ft_str_isalnum("Hello21World!") != 0)
|
||||
return (3);
|
||||
if (ft_str_isalnum("Hello420BlazeIt.") != 0)
|
||||
return (4);
|
||||
if (ft_str_isalnum("HelloWorld696969\0") != 1)
|
||||
return (5);
|
||||
if (ft_str_isalnum("") != 0)
|
||||
return (6);
|
||||
if (ft_str_isalnum(NULL) != false)
|
||||
return (7);
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_str/test_str_isalpha.c
Normal file
32
libft_personal/tests/ft_string/ft_str/test_str_isalpha.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:43:10 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isalpha(void)
|
||||
{
|
||||
if (ft_str_isalpha("HelloWorld") != 1)
|
||||
return (1);
|
||||
if (ft_str_isalpha("Hello World") != 0)
|
||||
return (2);
|
||||
if (ft_str_isalpha("HelloWorld!") != 0)
|
||||
return (3);
|
||||
if (ft_str_isalpha("HelloWorld42") != 0)
|
||||
return (4);
|
||||
if (ft_str_isalpha("HelloWorld\0") != 1)
|
||||
return (5);
|
||||
if (ft_str_isalpha("") != 0)
|
||||
return (6);
|
||||
if (ft_str_isalpha(NULL) != false)
|
||||
return (7);
|
||||
return (0);
|
||||
}
|
||||
36
libft_personal/tests/ft_string/ft_str/test_str_isbool.c
Normal file
36
libft_personal/tests/ft_string/ft_str/test_str_isbool.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isbool.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:22:20 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:43:20 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isbool(void)
|
||||
{
|
||||
if (ft_str_isbool("1") != 1 || ft_str_isbool("true") != 1)
|
||||
return (1);
|
||||
if (ft_str_isbool("0") != 1 || ft_str_isbool("false") != 1)
|
||||
return (2);
|
||||
if (ft_str_isbool("true!") != 0)
|
||||
return (3);
|
||||
if (ft_str_isbool("falseeurt") != 0)
|
||||
return (4);
|
||||
if (ft_str_isbool("truetrue") != 0)
|
||||
return (5);
|
||||
if (ft_str_isbool("false42") != 0)
|
||||
return (6);
|
||||
if (ft_str_isbool("false\t") != 0)
|
||||
return (7);
|
||||
if (ft_str_isbool("") != 0)
|
||||
return (8);
|
||||
if (ft_str_isbool(NULL) != false)
|
||||
return (9);
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_str/test_str_isdigit.c
Normal file
32
libft_personal/tests/ft_string/ft_str/test_str_isdigit.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:43:32 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isdigit(void)
|
||||
{
|
||||
if (ft_str_isdigit("00000000000000000000012") != 1)
|
||||
return (1);
|
||||
if (ft_str_isdigit("1234567890q") != 0)
|
||||
return (2);
|
||||
if (ft_str_isdigit("8^)") != 0)
|
||||
return (3);
|
||||
if (ft_str_isdigit("42.5") != 0)
|
||||
return (4);
|
||||
if (ft_str_isdigit("+00") != 0)
|
||||
return (5);
|
||||
if (ft_str_isdigit("") != 0)
|
||||
return (6);
|
||||
if (ft_str_isdigit(NULL) != false)
|
||||
return (7);
|
||||
return (0);
|
||||
}
|
||||
36
libft_personal/tests/ft_string/ft_str/test_str_isdouble.c
Normal file
36
libft_personal/tests/ft_string/ft_str/test_str_isdouble.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isdouble.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:43:42 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isdouble(void)
|
||||
{
|
||||
if (ft_str_isdouble("23.3") != 1 || ft_str_isdouble("42") != 1 || \
|
||||
ft_str_isdouble(".22") != 1 || ft_str_isdouble("0.0") != 1 || \
|
||||
ft_str_isdouble("2.000000") != 1 || ft_str_isdouble("0.000000") != 1)
|
||||
return (1);
|
||||
if (ft_str_isdouble("34..4") != 0)
|
||||
return (2);
|
||||
if (ft_str_isdouble("0a.0") != 0 || ft_str_isdouble("0.0a") != 0)
|
||||
return (3);
|
||||
if (ft_str_isdouble("0.0.0") != 0)
|
||||
return (4);
|
||||
if (ft_str_isdouble("-") != 0 || ft_str_isdouble("+") != 0 || \
|
||||
ft_str_isdouble("-.") != 0 || ft_str_isdouble("+.") != 0)
|
||||
return (5);
|
||||
if (ft_str_isdouble("94308243208523048750743") != 0 || \
|
||||
ft_str_isdouble("") != 0 || ft_str_isdouble(".") != 0)
|
||||
return (6);
|
||||
if (ft_str_isdouble(NULL) != false)
|
||||
return (7);
|
||||
return (0);
|
||||
}
|
||||
30
libft_personal/tests/ft_string/ft_str/test_str_isfloat.c
Normal file
30
libft_personal/tests/ft_string/ft_str/test_str_isfloat.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isfloat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:43:57 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isfloat(void)
|
||||
{
|
||||
if (ft_str_isfloat("23.3") != 1 || ft_str_isfloat("42") != 1 || \
|
||||
ft_str_isfloat(".22") != 1 || ft_str_isfloat("0.0") != 1 || \
|
||||
ft_str_isfloat("2.000000") != 1 || ft_str_isfloat("0.000000") != 1 || \
|
||||
ft_str_isfloat("-2") != 1 || ft_str_isfloat("2") != 1 || \
|
||||
ft_str_isfloat("2.") != 1 || ft_str_isfloat(".2") != 1)
|
||||
return (1);
|
||||
if (ft_str_isfloat("23.3.3") != 0 || \
|
||||
ft_str_isfloat("-") != 0 || ft_str_isfloat("+") != 0 || \
|
||||
ft_str_isfloat("") != 0)
|
||||
return (2);
|
||||
if (ft_str_isfloat(NULL) != false)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
38
libft_personal/tests/ft_string/ft_str/test_str_ishex.c
Normal file
38
libft_personal/tests/ft_string/ft_str/test_str_ishex.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_ishex.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:44:10 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_ishex(void)
|
||||
{
|
||||
if (ft_str_ishex("0123456789abcdefABCDEF") != 1)
|
||||
return (1);
|
||||
if (ft_str_ishex("0xdeadbeef") != 1 || ft_str_ishex("0xDEADBEEF") != 1)
|
||||
return (2);
|
||||
if (ft_str_ishex("0xdeadbeefg") != 0 || ft_str_ishex("0xDEADBEEFG") != 0)
|
||||
return (3);
|
||||
if (ft_str_ishex("0x") != 0 || ft_str_ishex("0X") != 0)
|
||||
return (4);
|
||||
if (ft_str_ishex("0x+32") != 0 || ft_str_ishex("0x-32") != 0)
|
||||
return (5);
|
||||
if (ft_str_ishex("0x0x") != 0 || ft_str_ishex("0X0X") != 0)
|
||||
return (6);
|
||||
if (ft_str_ishex("-0x0") != 0 || ft_str_ishex("+0X0") != 0)
|
||||
return (7);
|
||||
if (ft_str_ishex("0x0") != 1 || ft_str_ishex("0X0") != 1)
|
||||
return (8);
|
||||
if (ft_str_ishex("") != 0)
|
||||
return (8);
|
||||
if (ft_str_ishex(NULL) != false)
|
||||
return (9);
|
||||
return (0);
|
||||
}
|
||||
33
libft_personal/tests/ft_string/ft_str/test_str_isint.c
Normal file
33
libft_personal/tests/ft_string/ft_str/test_str_isint.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 09:11:09 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isint(void)
|
||||
{
|
||||
if (ft_str_isint("23") != 1 || ft_str_isint("42") != 1 || \
|
||||
ft_str_isint("0") != 1 || ft_str_isint("-42") != 1 || \
|
||||
ft_str_isint("2147483647") != 1 || ft_str_isint("-2147483648") != 1)
|
||||
return (1);
|
||||
if (ft_str_isint("23.3") != 0 || ft_str_isint("42.0") != 0 || \
|
||||
ft_str_isint("0.0") != 0 || ft_str_isint("2.000000") != 0 || \
|
||||
ft_str_isint("0.000000") != 0 || ft_str_isint("2147483648") != 0 || \
|
||||
ft_str_isint("-2147483649") != 0 || ft_str_isint("2147483647.0") != 0 || \
|
||||
ft_str_isint("-2147483648.0") != 0)
|
||||
return (2);
|
||||
if (ft_str_isint("") != 0 || ft_str_isint("999999999999") != 0 || \
|
||||
ft_str_isint("-") != 0 || ft_str_isint("+") != 0)
|
||||
return (3);
|
||||
if (ft_str_isint(NULL) != false)
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
39
libft_personal/tests/ft_string/ft_str/test_str_islong.c
Normal file
39
libft_personal/tests/ft_string/ft_str/test_str_islong.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_islong.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:44:27 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_islong(void)
|
||||
{
|
||||
if (ft_str_islong("23") != 1 || ft_str_islong("42") != 1 || \
|
||||
ft_str_islong("0") != 1 || ft_str_islong("2") != 1 || \
|
||||
ft_str_islong("-34") != 1 || ft_str_islong("42") != 1 || \
|
||||
ft_str_islong("9223372036854775807") != 1 || \
|
||||
ft_str_islong("-9223372036854775808") != 1)
|
||||
return (1);
|
||||
if (ft_str_islong("9223372036854775808") != 0 || \
|
||||
ft_str_islong("-9223372036854775809") != 0 || \
|
||||
ft_str_islong("92233720368547758070") != 0 || \
|
||||
ft_str_islong("-92233720368547758080") != 0 || \
|
||||
ft_str_islong("9223372036854775807a") != 0 || \
|
||||
ft_str_islong("-9223372036854775808a") != 0 || \
|
||||
ft_str_islong("9223372036854775807 ") != 0 || \
|
||||
ft_str_islong("-9223372036854775808 ") != 0 || \
|
||||
ft_str_islong("-+0") != 0 || ft_str_islong("+-0") != 0 || \
|
||||
ft_str_islong("0-") != 0 || ft_str_islong("0+") != 0)
|
||||
return (2);
|
||||
if (ft_str_islong("") != 0 || ft_str_islong("-") != 0)
|
||||
return (3);
|
||||
if (ft_str_islong(NULL) != false)
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_str/test_str_isnum.c
Normal file
32
libft_personal/tests/ft_string/ft_str/test_str_isnum.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:44:36 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isnum(void)
|
||||
{
|
||||
if (ft_str_isnum("-23") != 1 || ft_str_isnum("+42") != 1 || \
|
||||
ft_str_isnum("0") != 1 || ft_str_isnum("2345865785645643532453") != 1 || \
|
||||
ft_str_isnum("2147483647") != 1)
|
||||
return (1);
|
||||
if (ft_str_isnum("23.3") != 0 || ft_str_isnum("42.0") != 0 || \
|
||||
ft_str_isnum("0.0") != 0 || ft_str_isnum("2.000000") != 0 || \
|
||||
ft_str_isnum("0.000000") != 0 || ft_str_isnum("--2147483648") != 0 || \
|
||||
ft_str_isnum("++2147483648") != 0)
|
||||
return (2);
|
||||
if (ft_str_isnum("") != 0 || ft_str_isnum("+") != 0 || \
|
||||
ft_str_isnum("-") != 0)
|
||||
return (3);
|
||||
if (ft_str_isnum(NULL) != false)
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
28
libft_personal/tests/ft_string/ft_str/test_str_isoct.c
Normal file
28
libft_personal/tests/ft_string/ft_str/test_str_isoct.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isoct.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:45:10 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_isoct(void)
|
||||
{
|
||||
if (ft_str_isoct("0o1234567") != 1 || ft_str_isoct("0O1234567") != 1 || \
|
||||
ft_str_isoct("0o342") != 1 || ft_str_isoct("0o0") != 1 || \
|
||||
ft_str_isoct("0o000000") != 1)
|
||||
return (1);
|
||||
if (ft_str_isoct("-0o1234568") != 0 || ft_str_isoct("0o1234568") != 0 || \
|
||||
ft_str_isoct("0o9") != 0 || ft_str_isoct("12") != 0 || \
|
||||
ft_str_isoct("-7") != 0 || ft_str_isoct("+67") != 0)
|
||||
return (2);
|
||||
if (ft_str_isoct(NULL) != false)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
34
libft_personal/tests/ft_string/ft_str/test_str_isvalid.c
Normal file
34
libft_personal/tests/ft_string/ft_str/test_str_isvalid.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_isvalid.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/29 08:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:45:33 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int string_validator(int c)
|
||||
{
|
||||
return (c == 'a' || c == 'b' || c == 'c');
|
||||
}
|
||||
|
||||
int test_str_isvalid(void)
|
||||
{
|
||||
if (ft_str_isvalid("abc", string_validator) != 1 || ft_str_isvalid("abcabc",
|
||||
string_validator) != 1 || ft_str_isvalid("aabbcc",
|
||||
string_validator) != 1)
|
||||
return (1);
|
||||
if (ft_str_isvalid("abd", string_validator) != 0 || ft_str_isvalid("bap",
|
||||
string_validator) != 0 || ft_str_isvalid("ck",
|
||||
string_validator) != 0)
|
||||
return (2);
|
||||
if (ft_str_isvalid("", string_validator) != 0 || ft_str_isvalid(NULL,
|
||||
string_validator) != false)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_str/test_str_replace.c
Normal file
35
libft_personal/tests/ft_string/ft_str/test_str_replace.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_replace.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:52:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_replace(void)
|
||||
{
|
||||
char *str;
|
||||
char *res;
|
||||
|
||||
str = "Hello World!";
|
||||
res = ft_str_replace(str, "World", "Zod");
|
||||
if (ft_strcmp(res, "Hello Zod!") != 0)
|
||||
return (1);
|
||||
free(res);
|
||||
res = ft_str_replace(str, "World", "");
|
||||
if (ft_strcmp(res, "Hello !") != 0)
|
||||
return (2);
|
||||
free(res);
|
||||
str = "Hello World!";
|
||||
res = ft_str_replace(str, "toto", "tutu");
|
||||
if (ft_strcmp(res, "Hello World!") != 0)
|
||||
return (3);
|
||||
free(res);
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_str/test_str_replace_chr.c
Normal file
32
libft_personal/tests/ft_string/ft_str/test_str_replace_chr.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_str_replace_chr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:13:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:10:24 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_str_replace_chr(void)
|
||||
{
|
||||
char *str;
|
||||
char *res;
|
||||
|
||||
str = ft_strdup("Hello World!");
|
||||
res = ft_str_replace_chr(str, 'o', 'a');
|
||||
if (ft_strcmp(res, "Hella Warld!") != 0)
|
||||
return (1);
|
||||
free(res);
|
||||
str = ft_strdup("Hello World!");
|
||||
res = ft_str_replace_chr(str, 'o', '\0');
|
||||
if (ft_strcmp(res, "Hell") != 0 || ft_strcmp(res + 5, " W") != 0
|
||||
|| ft_strcmp(res + 8, "rld!") != 0)
|
||||
return (4);
|
||||
free(res);
|
||||
return (0);
|
||||
}
|
||||
40
libft_personal/tests/ft_string/ft_str/test_strappend_c.c
Normal file
40
libft_personal/tests/ft_string/ft_str/test_strappend_c.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strappend_c.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:12:40 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 08:08:07 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
// calloc sets the \0 byte at the end of the string
|
||||
// we test the function can append at empty string
|
||||
int test_strappend_c(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = ft_strdup("Hello");
|
||||
if (!str)
|
||||
return (1);
|
||||
if (ft_strappend_c(&str, ' ') == 0 || ft_strcmp(str, "Hello ") != 0)
|
||||
return (2);
|
||||
if (ft_strappend_c(&str, 'W') == 0 || ft_strcmp(str, "Hello W") != 0)
|
||||
return (3);
|
||||
if (ft_strappend_c(NULL, '\0'))
|
||||
return (4);
|
||||
free(str);
|
||||
str = ft_calloc(1, 1);
|
||||
if (!str || ft_strappend_c(&str, ' ') == 0 || ft_strcmp(str, " ") != 0)
|
||||
return (5);
|
||||
free(str);
|
||||
str = NULL;
|
||||
if (ft_strappend_c(&str, ' ') == 0 || ft_strcmp(str, " ") != 0)
|
||||
return (6);
|
||||
free(str);
|
||||
return (0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_str/test_strchr.c
Normal file
35
libft_personal/tests/ft_string/ft_str/test_strchr.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:12:40 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 07:51:50 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strchr(void)
|
||||
{
|
||||
char *str;
|
||||
char s;
|
||||
char s2;
|
||||
char *res;
|
||||
|
||||
str = "Hello World!";
|
||||
s = 'o';
|
||||
s2 = 'z';
|
||||
res = ft_strchr(str, s);
|
||||
if (res != str + 4)
|
||||
return (1);
|
||||
res = ft_strchr(str, s2);
|
||||
if (res)
|
||||
return (2);
|
||||
res = ft_strchr(str, '\0');
|
||||
if (res != str + ft_strlen(str))
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
28
libft_personal/tests/ft_string/ft_str/test_strclen.c
Normal file
28
libft_personal/tests/ft_string/ft_str/test_strclen.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strclen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 10:47:16 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 11:05:38 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strclen(void)
|
||||
{
|
||||
if (ft_strclen("Hello World", 'o') != 4)
|
||||
return (1);
|
||||
if (ft_strclen("Hello World", 'z') != 11)
|
||||
return (1);
|
||||
if (ft_strclen("Hello World", 'H') != 0)
|
||||
return (1);
|
||||
if (ft_strclen("Hello World", 'd') != 10)
|
||||
return (1);
|
||||
if (ft_strclen("Hello World", ' ') != 5)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_str/test_strcmp.c
Normal file
35
libft_personal/tests/ft_string/ft_str/test_strcmp.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:12:10 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/26 14:17:14 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strcmp(void)
|
||||
{
|
||||
const char *buffs[] = {
|
||||
"none",
|
||||
"some",
|
||||
"nonethensome",
|
||||
"nonethensome",
|
||||
"!\0a",
|
||||
"!\0b",
|
||||
};
|
||||
|
||||
if (ft_strcmp(buffs[0], buffs[1]) >= 0)
|
||||
return (1);
|
||||
if (ft_strcmp(buffs[0], buffs[2]) >= 0)
|
||||
return (2);
|
||||
if (ft_strcmp(buffs[2], buffs[3]) != 0)
|
||||
return (3);
|
||||
if (ft_strcmp(buffs[4], buffs[5]) != 0)
|
||||
return (4);
|
||||
return (0);
|
||||
}
|
||||
33
libft_personal/tests/ft_string/ft_str/test_strcnb.c
Normal file
33
libft_personal/tests/ft_string/ft_str/test_strcnb.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strcnb.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 10:47:58 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 08:06:11 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int test_strcnb(void)
|
||||
{
|
||||
if (ft_strcnb("Hello World", 'o') != 2)
|
||||
return (1);
|
||||
if (ft_strcnb("Hello World", 'z') != 0)
|
||||
return (2);
|
||||
if (ft_strcnb("Hello World", 'H') != 1)
|
||||
return (3);
|
||||
if (ft_strcnb("Hello World", 'd') != 1)
|
||||
return (4);
|
||||
if (ft_strcnb("Hello World", 'l') != 3)
|
||||
return (5);
|
||||
if (ft_strcnb(NULL, ' ') != 0)
|
||||
return (6);
|
||||
if (ft_strcnb("toto", '\0') != 1)
|
||||
return (7);
|
||||
return (0);
|
||||
}
|
||||
28
libft_personal/tests/ft_string/ft_str/test_strcspn.c
Normal file
28
libft_personal/tests/ft_string/ft_str/test_strcspn.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strcspn.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 10:48:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 11:03:55 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strcspn(void)
|
||||
{
|
||||
if (ft_strcspn("Hello World", "o") != 4)
|
||||
return (1);
|
||||
if (ft_strcspn("Hello World", "z") != 11)
|
||||
return (1);
|
||||
if (ft_strcspn("Hello World", "H") != 0)
|
||||
return (1);
|
||||
if (ft_strcspn("Hello World", "d") != 10)
|
||||
return (1);
|
||||
if (ft_strcspn("Hello World", " ") != 5)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
26
libft_personal/tests/ft_string/ft_str/test_strdup.c
Normal file
26
libft_personal/tests/ft_string/ft_str/test_strdup.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:23:17 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:10:32 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strdup(void)
|
||||
{
|
||||
char *str;
|
||||
char *res;
|
||||
|
||||
str = "Hello World!";
|
||||
res = ft_strdup(str);
|
||||
if (ft_strcmp(res, str) != 0)
|
||||
return (1);
|
||||
free(res);
|
||||
return (0);
|
||||
}
|
||||
28
libft_personal/tests/ft_string/ft_str/test_strend_with.c
Normal file
28
libft_personal/tests/ft_string/ft_str/test_strend_with.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strend_with.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 10:49:13 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 10:49:34 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strend_with(void)
|
||||
{
|
||||
if (ft_strend_with("Hello World", "World") != 1)
|
||||
return (1);
|
||||
if (ft_strend_with("Hello World", "World!") != 0)
|
||||
return (1);
|
||||
if (ft_strend_with("Hello World", "Hello") != 0)
|
||||
return (1);
|
||||
if (ft_strend_with("Hello World", "Hello World") != 1)
|
||||
return (1);
|
||||
if (ft_strend_with("Hello World", "Hello World!") != 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
33
libft_personal/tests/ft_string/ft_str/test_striteri.c
Normal file
33
libft_personal/tests/ft_string/ft_str/test_striteri.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:39:56 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 08:11:48 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
static void local_iteri(unsigned int i, char *c)
|
||||
{
|
||||
*c = 'a';
|
||||
(void)i;
|
||||
}
|
||||
|
||||
// last 2 calls are to test NULL protection
|
||||
int test_striteri(void)
|
||||
{
|
||||
char str[20];
|
||||
|
||||
ft_strlcpy(str, "Hello World!", 20);
|
||||
ft_striteri(str, &local_iteri);
|
||||
if (ft_strcmp(str, "aaaaaaaaaaaa") != 0)
|
||||
return (1);
|
||||
ft_striteri(NULL, &local_iteri);
|
||||
ft_striteri(str, NULL);
|
||||
return (0);
|
||||
}
|
||||
75
libft_personal/tests/ft_string/ft_str/test_strjoin.c
Normal file
75
libft_personal/tests/ft_string/ft_str/test_strjoin.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:11:19 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:10:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static int test_right_empty(void)
|
||||
{
|
||||
char *str;
|
||||
char *str2;
|
||||
char *res;
|
||||
|
||||
str = "Hello World!";
|
||||
str2 = "";
|
||||
res = ft_strjoin(str, str2);
|
||||
if (ft_strcmp(res, "Hello World!") != 0 || !res || res == str
|
||||
|| res == str2)
|
||||
return (1);
|
||||
free(res);
|
||||
str2 = NULL;
|
||||
res = ft_strjoin(str, str2);
|
||||
if (ft_strcmp(res, "Hello World!") != 0 || !res || res == str)
|
||||
return (2);
|
||||
free(res);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test_left_empty(void)
|
||||
{
|
||||
char *str;
|
||||
char *str2;
|
||||
char *res;
|
||||
|
||||
str = "";
|
||||
str2 = "Hello World!";
|
||||
res = ft_strjoin(str, str2);
|
||||
if (ft_strcmp(res, "Hello World!") != 0 || !res || res == str
|
||||
|| res == str2)
|
||||
return (1);
|
||||
free(res);
|
||||
str = NULL;
|
||||
res = ft_strjoin(str, str2);
|
||||
if (ft_strcmp(res, "Hello World!") != 0 || !res || res == str2)
|
||||
return (2);
|
||||
free(res);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int test_strjoin(void)
|
||||
{
|
||||
char *str;
|
||||
char *str2;
|
||||
char *res;
|
||||
|
||||
str = "Hello World!";
|
||||
str2 = "Hello World!";
|
||||
res = ft_strjoin(str, str2);
|
||||
if (ft_strcmp(res, "Hello World!Hello World!") != 0)
|
||||
return (1);
|
||||
free(res);
|
||||
if (test_right_empty() != 0)
|
||||
return (20 + test_right_empty());
|
||||
if (test_left_empty() != 0)
|
||||
return (30 + test_left_empty());
|
||||
return (0);
|
||||
}
|
||||
44
libft_personal/tests/ft_string/ft_str/test_strlcat.c
Normal file
44
libft_personal/tests/ft_string/ft_str/test_strlcat.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:11:01 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 08:24:26 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int test_strlcat(void)
|
||||
{
|
||||
char *res;
|
||||
size_t size;
|
||||
int ret;
|
||||
|
||||
size = 15;
|
||||
res = malloc(sizeof(char) * size);
|
||||
ft_bzero(res, size);
|
||||
ret = ft_strlcat(res, "Hello", size);
|
||||
if (ft_strcmp(res, "Hello") != 0 || ret != 5)
|
||||
return (1);
|
||||
ret = ft_strlcat(res, " World!", size);
|
||||
if (ft_strcmp(res, "Hello World!") != 0 || ret != 12)
|
||||
return (2);
|
||||
ret = ft_strlcat(res, "This is zod!", size);
|
||||
if (ft_strcmp(res, "Hello World!Th") != 0 || ret != 24)
|
||||
return (3);
|
||||
ret = ft_strlcat(res, "This is zod!", 5);
|
||||
if (ft_strcmp(res, "Hello World!Th") != 0 || ret != 5 + 12)
|
||||
return (4);
|
||||
if (ft_strlcat(NULL, "test", 0) != 0 || ft_strlcat(NULL, "test", 5) != 0)
|
||||
return (5);
|
||||
ret = ft_strlcat(res, NULL, size);
|
||||
if (ft_strcmp(res, "Hello World!Th") != 0 || ret != 14)
|
||||
return (6);
|
||||
return (free(res), 0);
|
||||
}
|
||||
74
libft_personal/tests/ft_string/ft_str/test_strlcpy.c
Normal file
74
libft_personal/tests/ft_string/ft_str/test_strlcpy.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:10:11 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 09:10:36 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int base_cases(void)
|
||||
{
|
||||
const char *str = "Hello World!";
|
||||
char *res;
|
||||
size_t size;
|
||||
int ret;
|
||||
|
||||
size = 15;
|
||||
res = ft_calloc(sizeof(char), size);
|
||||
ret = ft_strlcpy(res, str, size);
|
||||
if (ft_strcmp(res, "Hello World!") != 0 || ret != 12)
|
||||
return (1);
|
||||
free(res);
|
||||
res = malloc(sizeof(char) * size);
|
||||
ret = ft_strlcpy(res, "This is zod!", size);
|
||||
if (ft_strcmp(res, "This is zod!") != 0 || ret != 12)
|
||||
return (2);
|
||||
return (free(res), 0);
|
||||
}
|
||||
|
||||
static int error_cases(void)
|
||||
{
|
||||
char *res;
|
||||
size_t size;
|
||||
int ret;
|
||||
|
||||
size = 15;
|
||||
res = ft_calloc(sizeof(char), size);
|
||||
ret = ft_strlcpy(res, "This is too large!", size);
|
||||
if (ft_strncmp(res, "This is too large!", size - 1) != 0 || \
|
||||
ret != (int)ft_strlen("This is too large!"))
|
||||
return (3);
|
||||
free(res);
|
||||
res = ft_calloc(sizeof(char), 1);
|
||||
ret = ft_strlcpy(res, "Hello World!", 0);
|
||||
if (ft_strcmp(res, "") != 0 || ret != 12)
|
||||
return (4);
|
||||
ret = ft_strlcpy(res, NULL, 42);
|
||||
if (ft_strcmp(res, "") != 0 || ret != 0)
|
||||
return (5);
|
||||
ret = ft_strlcpy(NULL, "Hello World!", 42);
|
||||
if (ret != 42)
|
||||
return (6);
|
||||
return (free(res), 0);
|
||||
}
|
||||
|
||||
int test_strlcpy(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = base_cases();
|
||||
if (ret != 0)
|
||||
return (ret);
|
||||
ret = error_cases();
|
||||
if (ret != 0)
|
||||
return (ret + 10);
|
||||
return (0);
|
||||
}
|
||||
31
libft_personal/tests/ft_string/ft_str/test_strlen.c
Normal file
31
libft_personal/tests/ft_string/ft_str/test_strlen.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 12:26:06 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/26 12:26:07 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strlen(void)
|
||||
{
|
||||
char *str;
|
||||
char *str2;
|
||||
char *str3;
|
||||
|
||||
str = "Hello World!";
|
||||
str2 = "";
|
||||
str3 = "Hello\0World!";
|
||||
if (ft_strlen(str) != 12)
|
||||
return (1);
|
||||
if (ft_strlen(str2) != 0)
|
||||
return (2);
|
||||
if (ft_strlen(str3) != 5)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
43
libft_personal/tests/ft_string/ft_str/test_strmapi.c
Normal file
43
libft_personal/tests/ft_string/ft_str/test_strmapi.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:10:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 08:40:48 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static char local_mapi(unsigned int i, char c)
|
||||
{
|
||||
(void)i;
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (c + 32);
|
||||
return (c);
|
||||
}
|
||||
|
||||
int test_strmapi(void)
|
||||
{
|
||||
char *str;
|
||||
char *res;
|
||||
|
||||
str = "Hello World!";
|
||||
res = ft_strmapi(str, &local_mapi);
|
||||
if (ft_strcmp(res, "hELLO wORLD!") != 0)
|
||||
return (1);
|
||||
free(res);
|
||||
res = ft_strmapi(NULL, &local_mapi);
|
||||
if (res)
|
||||
return (2);
|
||||
res = ft_strmapi(str, NULL);
|
||||
if (res)
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
38
libft_personal/tests/ft_string/ft_str/test_strncmp.c
Normal file
38
libft_personal/tests/ft_string/ft_str/test_strncmp.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 12:23:03 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/26 12:23:05 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strncmp(void)
|
||||
{
|
||||
const char *str_buffs[] = {
|
||||
"none",
|
||||
"some",
|
||||
"nonethensome",
|
||||
"nonethensome",
|
||||
"!\0a",
|
||||
"!\0b",
|
||||
NULL
|
||||
};
|
||||
|
||||
if (ft_strncmp(str_buffs[0], str_buffs[1], 4) >= 0)
|
||||
return (1);
|
||||
if (ft_strncmp(str_buffs[0], str_buffs[2], 4) != 0)
|
||||
return (2);
|
||||
if (ft_strncmp(str_buffs[2], str_buffs[3], 4) != 0)
|
||||
return (3);
|
||||
if (ft_strncmp(str_buffs[4], str_buffs[5], 4) != 0)
|
||||
return (4);
|
||||
if (ft_strncmp(str_buffs[5], str_buffs[0], 0) != 0)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
38
libft_personal/tests/ft_string/ft_str/test_strndup.c
Normal file
38
libft_personal/tests/ft_string/ft_str/test_strndup.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strndup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:23:38 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:13:57 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strndup(void)
|
||||
{
|
||||
char *str;
|
||||
char *res;
|
||||
|
||||
str = "Hello World!";
|
||||
res = ft_strndup(str, 5);
|
||||
if (ft_strcmp(res, "Hello") != 0)
|
||||
return (1);
|
||||
free(res);
|
||||
res = ft_strndup(str, 0);
|
||||
if (ft_strcmp(res, "") != 0)
|
||||
return (2);
|
||||
free(res);
|
||||
res = ft_strndup(str, 12);
|
||||
if (ft_strcmp(res, "Hello World!") != 0)
|
||||
return (3);
|
||||
free(res);
|
||||
res = ft_strndup(str, 15);
|
||||
if (ft_strcmp(res, "Hello World!") != 0)
|
||||
return (4);
|
||||
free(res);
|
||||
return (0);
|
||||
}
|
||||
37
libft_personal/tests/ft_string/ft_str/test_strnstr.c
Normal file
37
libft_personal/tests/ft_string/ft_str/test_strnstr.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:24:10 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 08:44:18 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stddef.h>
|
||||
|
||||
int test_strnstr(void)
|
||||
{
|
||||
char *str;
|
||||
char *res;
|
||||
|
||||
str = "The cake is a lie !\0I'm hidden lol\n";
|
||||
if (ft_strnstr(str, "The cake is a lie !", 100) != str)
|
||||
return (1);
|
||||
if (ft_strnstr(str, "The cake is a lie !", 20) != str)
|
||||
return (2);
|
||||
res = ft_strnstr(str, "The cake is a lie !", 19);
|
||||
if (!res)
|
||||
return (3);
|
||||
if (ft_strnstr(str, "The cake is a lie !", 0))
|
||||
return (4);
|
||||
if (ft_strnstr(str, "hidden", 100))
|
||||
return (5);
|
||||
if (ft_strnstr(NULL, "hidden", 10) || \
|
||||
ft_strnstr(str, NULL, 10))
|
||||
return (6);
|
||||
return (0);
|
||||
}
|
||||
36
libft_personal/tests/ft_string/ft_str/test_strrchr.c
Normal file
36
libft_personal/tests/ft_string/ft_str/test_strrchr.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:41:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:14:12 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stddef.h>
|
||||
|
||||
int test_strrchr(void)
|
||||
{
|
||||
char *str;
|
||||
char s;
|
||||
char s2;
|
||||
char *res;
|
||||
|
||||
str = "Hello World!";
|
||||
s = 'o';
|
||||
s2 = 'z';
|
||||
res = ft_strrchr(str, s);
|
||||
if (res != str + 7)
|
||||
return (1);
|
||||
res = ft_strrchr(str, s2);
|
||||
if (res)
|
||||
return (2);
|
||||
res = ft_strrchr(str, '\0');
|
||||
if (res != str + ft_strlen(str))
|
||||
return (3);
|
||||
return (0);
|
||||
}
|
||||
28
libft_personal/tests/ft_string/ft_str/test_strspn.c
Normal file
28
libft_personal/tests/ft_string/ft_str/test_strspn.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strspn.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 10:48:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 11:05:30 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strspn(void)
|
||||
{
|
||||
if (ft_strspn("Hello World", "o") != 0)
|
||||
return (1);
|
||||
if (ft_strspn("Hello World", "z") != 0)
|
||||
return (1);
|
||||
if (ft_strspn("Hello World", "H") != 1)
|
||||
return (1);
|
||||
if (ft_strspn("Hello World", "d") != 0)
|
||||
return (1);
|
||||
if (ft_strspn("Hello World", "Helo Wrd") != 11)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
28
libft_personal/tests/ft_string/ft_str/test_strstart_with.c
Normal file
28
libft_personal/tests/ft_string/ft_str/test_strstart_with.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strstart_with.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 10:49:38 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/30 10:49:51 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strstart_with(void)
|
||||
{
|
||||
if (ft_strstart_with("Hello World", "Hello") != 1)
|
||||
return (1);
|
||||
if (ft_strstart_with("Hello World", "Hello!") != 0)
|
||||
return (1);
|
||||
if (ft_strstart_with("Hello World", "World") != 0)
|
||||
return (1);
|
||||
if (ft_strstart_with("Hello World", "Hello World") != 1)
|
||||
return (1);
|
||||
if (ft_strstart_with("Hello World", "Hello World!") != 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
39
libft_personal/tests/ft_string/ft_str/test_strtok.c
Normal file
39
libft_personal/tests/ft_string/ft_str/test_strtok.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strtok.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:24:49 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/25 21:43:49 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strtok(void)
|
||||
{
|
||||
char test[50];
|
||||
char lorem[30];
|
||||
|
||||
lorem[0] = '\0';
|
||||
test[0] = '\0';
|
||||
ft_strlcpy(lorem, "Lorem ipsum dolor ", 30);
|
||||
ft_strlcpy(test, ":::path/to/file:::another/path::yet/:/another/path", 47);
|
||||
if (ft_strcmp(ft_strtok(lorem, " "), "Lorem") != 0
|
||||
|| ft_strcmp(ft_strtok(NULL, " "), "ipsum") != 0
|
||||
|| ft_strcmp(ft_strtok(NULL, " "), "dolor") != 0)
|
||||
return (1);
|
||||
if (ft_strcmp(ft_strtok(NULL, " "), "") != 0 || ft_strtok(NULL,
|
||||
" "))
|
||||
return (2);
|
||||
if (ft_strcmp(ft_strtok(test, ":"), "path/to/file") != 0
|
||||
|| ft_strcmp(ft_strtok(NULL, ":"), "another/path") != 0)
|
||||
return (3);
|
||||
if (ft_strcmp(ft_strtok(NULL, ":/"), "yet") != 0)
|
||||
return (4);
|
||||
if (ft_strcmp(ft_strtok(NULL, ":/"), "another") != 0)
|
||||
return (5);
|
||||
return (0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_str/test_strtrim.c
Normal file
35
libft_personal/tests/ft_string/ft_str/test_strtrim.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:19:56 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 09:00:33 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_strtrim(void)
|
||||
{
|
||||
const char *str_ugly = " Hello World! ";
|
||||
const char *str_ugly_front = " Hello World!";
|
||||
char *res[7];
|
||||
|
||||
res[0] = ft_strtrim(ft_strchr(str_ugly, 'H'), " ");
|
||||
res[1] = ft_strtrim(str_ugly, " ");
|
||||
res[2] = ft_strtrim(str_ugly_front, " ");
|
||||
res[3] = ft_strtrim(str_ugly, " !Wd");
|
||||
res[4] = ft_strtrim(str_ugly, NULL);
|
||||
res[5] = ft_strtrim(" ", " ");
|
||||
res[6] = ft_strtrim(NULL, " ");
|
||||
if (ft_strcmp(res[0], "Hello World!") != 0 || ft_strcmp(res[1], \
|
||||
"Hello World!") != 0 || ft_strcmp(res[2], "Hello World!") != 0 || \
|
||||
ft_strcmp(res[3], "Hello Worl") != 0 || ft_strcmp(res[4], str_ugly) \
|
||||
!= 0 || ft_strcmp(res[5], "") != 0 || res[6])
|
||||
return (1);
|
||||
ft_apply_2d((void **)res, free);
|
||||
return (0);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_str/test_substr.c
Normal file
35
libft_personal/tests/ft_string/ft_str/test_substr.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 12:25:34 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 09:02:53 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
|
||||
int test_substr(void)
|
||||
{
|
||||
const char *str = "Hello World!";
|
||||
char *res[7];
|
||||
|
||||
res[0] = ft_substr(str, 0, 5);
|
||||
res[1] = ft_substr(str, 6, 6);
|
||||
res[2] = ft_substr(str, 6, 100);
|
||||
res[3] = ft_substr(str, 6, 0);
|
||||
res[4] = ft_substr(str, 12, 0);
|
||||
res[5] = ft_substr(str, 12, 100);
|
||||
res[6] = ft_substr(NULL, 0, 5);
|
||||
if (ft_strcmp(res[0], "Hello") != 0 || ft_strcmp(res[1], "World!") != 0
|
||||
|| ft_strcmp(res[2], "World!") != 0)
|
||||
return (1);
|
||||
if (ft_strcmp(res[3], "") != 0 || ft_strcmp(res[4], "") != 0
|
||||
|| ft_strcmp(res[5], "") != 0 || res[6])
|
||||
return (2);
|
||||
ft_apply_2d((void **)res, free);
|
||||
return (0);
|
||||
}
|
||||
33
libft_personal/tests/ft_string/ft_str/test_utoa.c
Normal file
33
libft_personal/tests/ft_string/ft_str/test_utoa.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_utoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/26 11:17:28 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 15:39:44 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int test_utoa(void)
|
||||
{
|
||||
char *res;
|
||||
size_t i;
|
||||
const unsigned int t_cases[] = {0, 123, 456, 7890, 12345};
|
||||
const char *expected_results[] = \
|
||||
{"0", "123", "456", "7890", "12345"};
|
||||
|
||||
i = 0;
|
||||
while (i < sizeof(t_cases) / sizeof(t_cases[0]))
|
||||
{
|
||||
res = ft_utoa(t_cases[i]);
|
||||
if (ft_strcmp(res, expected_results[i++]) != 0)
|
||||
return (i);
|
||||
free(res);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
60
libft_personal/tests/ft_string/ft_string/t_string_tests.c
Normal file
60
libft_personal/tests/ft_string/ft_string/t_string_tests.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* t_string_tests.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/30 13:39:25 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/01 12:36:14 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tests/str__t_str_test.h"
|
||||
#include "tests/tests.h"
|
||||
|
||||
static const t_test *loadtests01(void)
|
||||
{
|
||||
static const t_test tests[] = {
|
||||
{"append_c", test_string_append_c}, {"append_n", test_string_append_n},
|
||||
{"append_sn", test_string_append_sn}, {"append_s", test_string_append_s},
|
||||
{"append", test_string_append}, {"cap", test_string_cap},
|
||||
{"chr", test_string_chr}, {"clear", test_string_clear},
|
||||
{"cmp_str", test_string_cmp_str}, {"cmp", test_string_cmp},
|
||||
{"destroy", test_string_destroy}, {"from_c", test_string_from_c},
|
||||
{"from_n", test_string_from_n}, {"from_sn", test_string_from_sn},
|
||||
{"from_s", test_string_from_s}, {"from", test_string_from},
|
||||
{"get", test_string_get}, {"insert_c", test_string_insert_c},
|
||||
{"insert_n", test_string_insert_n}, {"insert_sn", test_string_insert_sn},
|
||||
{"insert_s", test_string_insert_s}, {"insert", test_string_insert},
|
||||
{"length", test_string_len}, {"ncmp_str", test_string_ncmp_str},
|
||||
{"ncmp", test_string_ncmp}, {"new", test_string_new},
|
||||
{"offset", test_string_offset}, {"put", test_string_put},
|
||||
{"rchr", test_string_rchr}, {"replace_c", test_string_replace_chr},
|
||||
{"replace", test_string_replace}, {"reserve", test_string_reserve},
|
||||
{"resize", test_string_resize}, {"roffset", test_string_roffset},
|
||||
{"set", test_string_set}, {"set_n", test_string_set_n},
|
||||
{"set_inplace", test_string_set_inplace}, {"shrink", test_string_shrink},
|
||||
{"substr", test_string_substr}, {"to_str", test_string_to_str},
|
||||
{"trim_chr", test_string_trim_chr}, {"trimstr", test_string_trimstr},
|
||||
{"trim", test_string_trim}, {NULL, NULL}};
|
||||
|
||||
return (tests);
|
||||
}
|
||||
|
||||
static const t_test *loadtests02(void)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int t_string_tests(void)
|
||||
{
|
||||
int sum;
|
||||
const t_test *tests = loadtests01();
|
||||
const t_test *tests02 = loadtests02();
|
||||
|
||||
sum = 0;
|
||||
(void)tests02;
|
||||
run_test(tests, &sum);
|
||||
return (sum);
|
||||
}
|
||||
35
libft_personal/tests/ft_string/ft_string/test_append.c
Normal file
35
libft_personal/tests/ft_string/ft_string/test_append.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_append.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 15:57:50 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 10:24:16 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_append(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
ft_string_append(str, " World");
|
||||
if (ft_string_cmp(str, "Hello World") != 0)
|
||||
return (1);
|
||||
if (str->length != 11 || str->capacity < 11)
|
||||
return (2);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from("hi");
|
||||
ft_string_append(str, "i");
|
||||
if (ft_string_cmp(str, "hii") != 0)
|
||||
return (3);
|
||||
if (str->length != 3 || str->capacity < 3)
|
||||
return (4);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
37
libft_personal/tests/ft_string/ft_string/test_append_c.c
Normal file
37
libft_personal/tests/ft_string/ft_string/test_append_c.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_append_c.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 15:57:32 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 10:26:58 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
// second test for ft_string_append_c is to check in case buffer is greater
|
||||
// than current lenght that char will be indeed appended
|
||||
int test_string_append_c(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
ft_string_append_c(str, ' ');
|
||||
if (ft_string_cmp(str, "Hello ") != 0)
|
||||
return (1);
|
||||
if (str->length != 6 || str->capacity < 6)
|
||||
return (2);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from("hi");
|
||||
ft_string_append_c(str, 'i');
|
||||
if (ft_string_cmp(str, "hii") != 0)
|
||||
return (3);
|
||||
if (str->length != 3 || str->capacity < 3)
|
||||
return (4);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
37
libft_personal/tests/ft_string/ft_string/test_append_n.c
Normal file
37
libft_personal/tests/ft_string/ft_string/test_append_n.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_append_n.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 15:57:05 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 10:27:16 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_append_n(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
ft_string_append_n(str, " World", 5);
|
||||
if (ft_string_cmp(str, "Hello Worl") != 0)
|
||||
return (1);
|
||||
if (str->length != 10)
|
||||
return (2);
|
||||
if (str->capacity < 10)
|
||||
return (3);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from("hi");
|
||||
ft_string_append_n(str, "i", 1);
|
||||
if (ft_string_cmp(str, "hii") != 0)
|
||||
return (4);
|
||||
if (str->length != 3 || str->capacity < 3)
|
||||
return (5);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
40
libft_personal/tests/ft_string/ft_string/test_append_s.c
Normal file
40
libft_personal/tests/ft_string/ft_string/test_append_s.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_append_s.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 15:56:56 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 10:27:43 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_append_s(void)
|
||||
{
|
||||
t_string *str;
|
||||
t_string *str2;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
str2 = ft_string_from(" World");
|
||||
ft_string_append_s(str, str2);
|
||||
if (ft_string_cmp(str, "Hello World") != 0)
|
||||
return (1);
|
||||
if (str->length != 11)
|
||||
return (2);
|
||||
if (str->capacity < 11)
|
||||
return (3);
|
||||
ft_string_destroy(&str);
|
||||
ft_string_destroy(&str2);
|
||||
str = ft_string_from("hi");
|
||||
str2 = ft_string_from("i");
|
||||
ft_string_append_s(str, str2);
|
||||
if (ft_string_cmp(str, "hii") != 0)
|
||||
return (4);
|
||||
if (str->length != 3 || str->capacity < 3)
|
||||
return (5);
|
||||
return (ft_string_destroy(&str), ft_string_destroy(&str2), 0);
|
||||
}
|
||||
38
libft_personal/tests/ft_string/ft_string/test_append_sn.c
Normal file
38
libft_personal/tests/ft_string/ft_string/test_append_sn.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_append_sn.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 15:55:52 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 10:30:24 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_append_sn(void)
|
||||
{
|
||||
t_string *str;
|
||||
t_string *str2;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
str2 = ft_string_from(" World!!!!");
|
||||
ft_string_append_s_n(str, str2, 6);
|
||||
if (ft_string_cmp(str, "Hello World") != 0)
|
||||
return (1);
|
||||
if (str->length != 11 || str->capacity < 11)
|
||||
return (2);
|
||||
ft_string_destroy(&str);
|
||||
ft_string_destroy(&str2);
|
||||
str = ft_string_from("hi");
|
||||
str2 = ft_string_from("ii");
|
||||
ft_string_append_s_n(str, str2, 1);
|
||||
if (ft_string_cmp(str, "hii") != 0)
|
||||
return (3);
|
||||
if (str->length != 3 || str->capacity < 3)
|
||||
return (4);
|
||||
return (ft_string_destroy(&str), ft_string_destroy(&str2), 0);
|
||||
}
|
||||
25
libft_personal/tests/ft_string/ft_string/test_cap.c
Normal file
25
libft_personal/tests/ft_string/ft_string/test_cap.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_t_str_cap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 15:57:50 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 12:21:38 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_cap(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello world this is zod!");
|
||||
if (str->capacity != ft_string_cap(str))
|
||||
return (1);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
34
libft_personal/tests/ft_string/ft_string/test_chr.c
Normal file
34
libft_personal/tests/ft_string/ft_string/test_chr.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_chr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 15:57:50 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 10:35:34 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_chr(void)
|
||||
{
|
||||
t_string *str;
|
||||
const char c[] = "z!H@\0";
|
||||
char *ptr_exp[sizeof(c) / sizeof(c[0])];
|
||||
size_t i;
|
||||
|
||||
str = ft_string_from("Hello world this is zod!");
|
||||
i = 0;
|
||||
while (i < sizeof(c) / sizeof(c[0]))
|
||||
{
|
||||
ptr_exp[i] = ft_strchr(str->str, c[i]);
|
||||
if (ft_string_chr(str, c[i]) != ptr_exp[i])
|
||||
return (i + 1);
|
||||
i++;
|
||||
}
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_string/test_clear.c
Normal file
32
libft_personal/tests/ft_string/ft_string/test_clear.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_t_str_clear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 12:21:38 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_clear(void)
|
||||
{
|
||||
t_string *str;
|
||||
size_t capacity;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
capacity = str->capacity;
|
||||
ft_string_clear(str);
|
||||
if (ft_string_cmp(str, "") != 0)
|
||||
return (1);
|
||||
if (str->length != 0)
|
||||
return (2);
|
||||
if (str->capacity != capacity)
|
||||
return (3);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
33
libft_personal/tests/ft_string/ft_string/test_cmp.c
Normal file
33
libft_personal/tests/ft_string/ft_string/test_cmp.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_cmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 19:20:23 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_cmp(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello World");
|
||||
if (ft_string_cmp(str, "Hello World") != 0)
|
||||
return (1);
|
||||
if (ft_string_cmp(str, "Hello Warld!") != 'o' - 'a')
|
||||
return (2);
|
||||
if (ft_string_cmp(str, "Hello Wprld!") != 'o' - 'p')
|
||||
return (3);
|
||||
if (ft_string_cmp(str, "Hello World!") != '\0' - '!')
|
||||
return (4);
|
||||
if (ft_string_cmp(str, "Hell") != 'o' - '\0')
|
||||
return (5);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
36
libft_personal/tests/ft_string/ft_string/test_cmp_str.c
Normal file
36
libft_personal/tests/ft_string/ft_string/test_cmp_str.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_cmp_str.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/03 11:01:15 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_cmp_str(void)
|
||||
{
|
||||
t_string *str;
|
||||
t_string *str2;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
str2 = ft_string_from("Hello");
|
||||
if (ft_string_cmpstr(str, str2) != 0)
|
||||
return (1);
|
||||
ft_string_destroy(&str2);
|
||||
str2 = ft_string_from("Hello World");
|
||||
if (ft_string_cmpstr(str, str2) >= 0)
|
||||
return (2);
|
||||
ft_string_destroy(&str2);
|
||||
str2 = ft_string_from("Hell");
|
||||
if (ft_string_cmpstr(str, str2) <= 0)
|
||||
return (3);
|
||||
ft_string_destroy(&str);
|
||||
ft_string_destroy(&str2);
|
||||
return (0);
|
||||
}
|
||||
31
libft_personal/tests/ft_string/ft_string/test_destroy.c
Normal file
31
libft_personal/tests/ft_string/ft_string/test_destroy.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_t_str_destroy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/25 17:37:36 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
/*
|
||||
ft_string_destroy(&str); // null resiliancy
|
||||
ft_string_destroy(NULL); // null resiliancy
|
||||
*/
|
||||
int test_string_destroy(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
ft_string_destroy(&str);
|
||||
if (str)
|
||||
return (1);
|
||||
ft_string_destroy(&str);
|
||||
ft_string_destroy(NULL);
|
||||
return (0);
|
||||
}
|
||||
31
libft_personal/tests/ft_string/ft_string/test_from.c
Normal file
31
libft_personal/tests/ft_string/ft_string/test_from.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_from.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 19:35:08 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_from(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello World");
|
||||
if (ft_string_cmp(str, "Hello World") != 0)
|
||||
return (1);
|
||||
if (str->length != 11 || str->capacity < 11)
|
||||
return (2);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from(NULL);
|
||||
if (str->length != 0 || str->capacity < 1)
|
||||
return (3);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
29
libft_personal/tests/ft_string/ft_string/test_from_c.c
Normal file
29
libft_personal/tests/ft_string/ft_string/test_from_c.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_t_str_from_c.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 12:21:38 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_from_c(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from_c('c');
|
||||
if (ft_string_cmp(str, "c") != 0)
|
||||
return (1);
|
||||
if (str->length != 1)
|
||||
return (2);
|
||||
if (str->capacity < 1)
|
||||
return (3);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
34
libft_personal/tests/ft_string/ft_string/test_from_n.c
Normal file
34
libft_personal/tests/ft_string/ft_string/test_from_n.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_from_n.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 19:36:12 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_from_n(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from_n("Hello World", 5);
|
||||
if (ft_string_cmp(str, "Hello") != 0)
|
||||
return (1);
|
||||
if (str->length != 5 || str->capacity < 5)
|
||||
return (2);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from_n(NULL, 5);
|
||||
if (str->length != 0 || str->capacity < 1)
|
||||
return (3);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from_n("Hello World", 0);
|
||||
if (str->length != 0 || str->capacity < 1)
|
||||
return (4);
|
||||
return (ft_string_destroy(&str), 0);
|
||||
}
|
||||
32
libft_personal/tests/ft_string/ft_string/test_from_s.c
Normal file
32
libft_personal/tests/ft_string/ft_string/test_from_s.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_from_s.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 19:38:05 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_from_s(void)
|
||||
{
|
||||
t_string *str;
|
||||
t_string *str_src;
|
||||
|
||||
str_src = ft_string_from("Hello World");
|
||||
str = ft_string_from_s(str_src);
|
||||
if (ft_string_cmp(str, "Hello World") != 0)
|
||||
return (1);
|
||||
if (str->length != 11 || str->capacity < 11)
|
||||
return (2);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from_s(NULL);
|
||||
if (str->length != 0 || str->capacity < 1)
|
||||
return (3);
|
||||
return (ft_string_destroy(&str), ft_string_destroy(&str_src), 0);
|
||||
}
|
||||
38
libft_personal/tests/ft_string/ft_string/test_from_sn.c
Normal file
38
libft_personal/tests/ft_string/ft_string/test_from_sn.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_from_sn.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/02 19:41:58 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_from_sn(void)
|
||||
{
|
||||
t_string *str;
|
||||
t_string *str_src;
|
||||
|
||||
str_src = ft_string_from("Hello World");
|
||||
str = ft_string_from_s_n(str_src, 5);
|
||||
if (ft_string_cmp(str, "Hello") != 0)
|
||||
return (1);
|
||||
if (str->length != 5)
|
||||
return (2);
|
||||
if (str->capacity < 5)
|
||||
return (3);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from_s_n(NULL, 5);
|
||||
if (str->length != 0 || str->capacity < 1)
|
||||
return (4);
|
||||
ft_string_destroy(&str);
|
||||
str = ft_string_from_s_n(str_src, 0);
|
||||
if (str->length != 0 || str->capacity < 1)
|
||||
return (5);
|
||||
return (ft_string_destroy(&str), ft_string_destroy(&str_src), 0);
|
||||
}
|
||||
27
libft_personal/tests/ft_string/ft_string/test_get.c
Normal file
27
libft_personal/tests/ft_string/ft_string/test_get.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tests_t_str_get.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/31 06:21:54 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/05/31 12:21:38 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_get(void)
|
||||
{
|
||||
t_string *str;
|
||||
const char *c_str;
|
||||
|
||||
str = ft_string_from("Hello worlds!");
|
||||
c_str = ft_string_get(str);
|
||||
if (ft_strncmp(str->str, c_str, str->length) != 0)
|
||||
return (1);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
33
libft_personal/tests/ft_string/ft_string/test_insert.c
Normal file
33
libft_personal/tests/ft_string/ft_string/test_insert.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_insert.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/03 10:14:37 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_insert(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
ft_string_insert(str, " World", 0);
|
||||
if (ft_string_cmp(str, " WorldHello") != 0)
|
||||
return (1);
|
||||
if (str->length != 11 || str->capacity < 11)
|
||||
return (2);
|
||||
ft_string_insert(str, "!", 99);
|
||||
if (ft_string_cmp(str, " WorldHello!") != 0)
|
||||
return (3);
|
||||
if (str->length != 12 || str->capacity < 12)
|
||||
return (4);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
33
libft_personal/tests/ft_string/ft_string/test_insert_c.c
Normal file
33
libft_personal/tests/ft_string/ft_string/test_insert_c.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_insert_c.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/25 17:34:36 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/06/03 10:15:26 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_string.h"
|
||||
#include "ft_string_types.h"
|
||||
|
||||
int test_string_insert_c(void)
|
||||
{
|
||||
t_string *str;
|
||||
|
||||
str = ft_string_from("Hello");
|
||||
ft_string_insert_c(str, ' ', 0);
|
||||
if (ft_string_cmp(str, " Hello") != 0)
|
||||
return (1);
|
||||
if (str->length != 6 || str->capacity < 6)
|
||||
return (2);
|
||||
ft_string_insert_c(str, '!', 99);
|
||||
if (ft_string_cmp(str, " Hello!") != 0)
|
||||
return (3);
|
||||
if (str->length != 7 || str->capacity < 7)
|
||||
return (4);
|
||||
ft_string_destroy(&str);
|
||||
return (0);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue