removing the libft of rparodi
This commit is contained in:
parent
0391323626
commit
be6038dcc8
523 changed files with 724 additions and 3336 deletions
32
libft/tests/ft_string/ft_mem/mem_tests.c
Normal file
32
libft/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/tests/ft_string/ft_mem/tests_apply_2d.c
Normal file
41
libft/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/tests/ft_string/ft_mem/tests_bzero.c
Normal file
25
libft/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/tests/ft_string/ft_mem/tests_calloc.c
Normal file
33
libft/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/tests/ft_string/ft_mem/tests_fd_to_buff.c
Normal file
71
libft/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/tests/ft_string/ft_mem/tests_free.c
Normal file
26
libft/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/tests/ft_string/ft_mem/tests_free_2d.c
Normal file
24
libft/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/tests/ft_string/ft_mem/tests_len_2d.c
Normal file
26
libft/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/tests/ft_string/ft_mem/tests_memchr.c
Normal file
32
libft/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/tests/ft_string/ft_mem/tests_memcmp.c
Normal file
35
libft/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/tests/ft_string/ft_mem/tests_memcpy.c
Normal file
31
libft/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/tests/ft_string/ft_mem/tests_memmap.c
Normal file
40
libft/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/tests/ft_string/ft_mem/tests_memmove.c
Normal file
37
libft/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/tests/ft_string/ft_mem/tests_memset.c
Normal file
37
libft/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/tests/ft_string/ft_mem/tests_qsort.c
Normal file
31
libft/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/tests/ft_string/ft_mem/tests_realloc.c
Normal file
31
libft/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/tests/ft_string/ft_mem/tests_swap.c
Normal file
32
libft/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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue