refactor(test): modifying test to be easier to read

This commit is contained in:
Raphael 2025-12-13 13:35:04 +01:00
parent 6faf9d51a4
commit b4196550be
No known key found for this signature in database

View file

@ -93,6 +93,32 @@ static void _test_strcmp()
putchar('\n');
}
static void _test_strcpy(void)
{
printf("\n%sTesting '%sstrcpy%s'%s\n", CLR_YELLOW, CLR_BLUE, CLR_YELLOW, RESET);
ft_strcpy(NULL, "a");
printf("%s✔%s ", CLR_GREEN, RESET);
ft_strcpy("a", NULL);
printf("%s✔%s ", CLR_GREEN, RESET);
ft_strcpy(NULL, NULL);
printf("%s✔%s ", CLR_GREEN, RESET);
for (int i = 0; strs[i]; i++)
{
char buf_orig[8192];
char buf_home[8192];
memset(buf_orig, 0, sizeof(buf_orig));
memset(buf_home, 0, sizeof(buf_home));
char *ret_orig = strcpy(buf_orig, strs[i]);
char *ret_home = ft_strcpy(buf_home, strs[i]);
if (strcmp(buf_orig, buf_home) == 0 && ret_orig == buf_orig && ret_home == buf_home)
printf("%s✔%s", CLR_GREEN, RESET);
else
dprintf(2, "\t%s✘%s", CLR_RED, RESET);
putchar(' ');
}
putchar('\n');
}
static void _test_write(void)
{
int original, homemade;
@ -191,6 +217,7 @@ int main(int argc, char *argv[])
t_test_func tests[] = {
_test_strlen,
_test_strcmp,
_test_strcpy,
_test_write,
_test_read,
NULL
@ -198,6 +225,7 @@ int main(int argc, char *argv[])
char *func_name[] = {
"strlen",
"strcmp",
"strcpy",
"write",
"read",
NULL