test(convert): adding test to convert
- adding test for atoi / atoll / itoa - Maybe a futur update to test atost (array to size_t)
This commit is contained in:
parent
aa8544ba02
commit
18f174b2a2
3 changed files with 125 additions and 0 deletions
41
test/convert/test_atoi.c
Normal file
41
test/convert/test_atoi.c
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* test_atoi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/09/05 15:05:21 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include "convert.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const char *str[] = {"", "0", "42", "-42", "+-42", "-2147483648",
|
||||||
|
"2147483647"};
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < 7)
|
||||||
|
{
|
||||||
|
if (ft_atoi(str[i]) != atoi(str[i]))
|
||||||
|
{
|
||||||
|
dprintf(2, "%s✘ Found %i, expected %i%s\n", CLR_RED,
|
||||||
|
ft_atoi(str[i]), atoi(str[i]), RESET);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
ft_atoi(NULL);
|
||||||
|
printf("%s✔%s", CLR_GREEN, RESET);
|
||||||
|
puts("\n");
|
||||||
|
}
|
||||||
41
test/convert/test_atoll.c
Normal file
41
test/convert/test_atoll.c
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* test_atoll.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/09/05 15:05:31 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include "convert.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const char *str[] = {"", "0", "42", "-42", "+-42", "-2147483648",
|
||||||
|
"2147483647", "9223372036854775807", "-9223372036854775808"};
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < 7)
|
||||||
|
{
|
||||||
|
if (ft_atoll(str[i]) != atoll(str[i]))
|
||||||
|
{
|
||||||
|
dprintf(2, "%s✘ Found %lli, expected %lli%s\n", CLR_RED,
|
||||||
|
ft_atoll(str[i]), atoll(str[i]), RESET);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
ft_atoll(NULL);
|
||||||
|
printf("%s✔%s", CLR_GREEN, RESET);
|
||||||
|
puts("\n");
|
||||||
|
}
|
||||||
43
test/convert/test_itoa.c
Normal file
43
test/convert/test_itoa.c
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* test_itoa.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/09/05 15:08:52 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include "convert.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const int integer[] = {0, 42, -42, +-42, -2147483648, 2147483647};
|
||||||
|
char result[1024];
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < 7)
|
||||||
|
{
|
||||||
|
sprintf(result, "%d", integer[i]);
|
||||||
|
if (strcmp(ft_itoa(integer[i]), result))
|
||||||
|
{
|
||||||
|
dprintf(2, "%s✘ Found %s, expected %s%s\n", CLR_RED,
|
||||||
|
ft_itoa(integer[i]), result, RESET);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
ft_atoi(NULL);
|
||||||
|
printf("%s✔%s", CLR_GREEN, RESET);
|
||||||
|
puts("\n");
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue