🧪 Unit Test Update – Character Functions
🎯 Gameplay Fixes (a.k.a. Function Corrections) • 🔧 ft_isascii has been rebalanced: now consistently returns 1 for values within the ASCII range (0–127), instead of leaking the raw character value. • 🔧 ft_isprint has been patched: returns 1 only for printable characters (32–126), aligning with the standard library. ➡️ These fixes bring our character classification system fully in line with the C standard behavior. No more unfair RNG in return values! ⸻ 🆕 New Content (a.k.a. Fresh Test Files) • 📜 test_isascii.c – Exhaustively tests ft_isascii vs isascii across values 0–128. • 📜 test_isprint.c – Pits ft_isprint against isprint across the same range. • 📜 test_tolower.c – Validates ft_tolower against tolower. • 📜 test_toupper.c – Validates ft_toupper against toupper. ⸻ ⚡ Impact • Consistent, predictable behavior for all classification and transformation functions. • A stronger, more reliable unit test suite to guard against future regressions. • Confidence boost for upcoming boss fights (👀 the rest of libft).
This commit is contained in:
commit
3aa050dff6
6 changed files with 148 additions and 4 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:04:26 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/04 11:41:42 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 10:40:03 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,6 +21,6 @@ int ft_isascii(int c)
|
|||
if (c == 0)
|
||||
return (1);
|
||||
if (c > 0 && c <= 127)
|
||||
return (c);
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:06:53 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/04 11:41:49 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 10:44:13 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,6 +19,6 @@
|
|||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (c);
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
36
test/char/test_isascii.c
Normal file
36
test/char/test_isascii.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 10:40:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "char.h"
|
||||
#include "color.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = 0;
|
||||
while (c <= 128)
|
||||
{
|
||||
if (ft_isascii(c) != isascii(c))
|
||||
{
|
||||
printf("%s✘ Found %i, excepted %i%s\n", CLR_RED, ft_isascii(c),
|
||||
isascii(c), RESET);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
36
test/char/test_isprint.c
Normal file
36
test/char/test_isprint.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 10:43:55 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "char.h"
|
||||
#include "color.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = 0;
|
||||
while (c <= 128)
|
||||
{
|
||||
if (ft_isprint(c) != isprint(c))
|
||||
{
|
||||
printf("%s✘ Found %i, excepted %i%s\n", CLR_RED, ft_isprint(c),
|
||||
isprint(c), RESET);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
36
test/char/test_tolower.c
Normal file
36
test/char/test_tolower.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 10:35:53 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "char.h"
|
||||
#include "color.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = 0;
|
||||
while (c <= 128)
|
||||
{
|
||||
if (ft_tolower(c) != tolower(c))
|
||||
{
|
||||
printf("%s✘ Found %i, excepted %i%s\n", CLR_RED, ft_tolower(c),
|
||||
tolower(c), RESET);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
36
test/char/test_toupper.c
Normal file
36
test/char/test_toupper.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 10:37:26 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "char.h"
|
||||
#include "color.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
c = 0;
|
||||
while (c <= 128)
|
||||
{
|
||||
if (ft_toupper(c) != toupper(c))
|
||||
{
|
||||
printf("%s✘ Found %i, excepted %i%s\n", CLR_RED, ft_toupper(c),
|
||||
toupper(c), RESET);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue