aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_atoi.c
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-21 15:49:06 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-21 15:51:44 +0100
commit671a58519ef6207b54947ff70eea497ff7eb58ae (patch)
tree783a971119bfed965113b84bc306ba941e884663 /tests/test_atoi.c
parentd699849b2360f90c61f645c5d4d4232cd3e1c962 (diff)
downloadLibft-671a58519ef6207b54947ff70eea497ff7eb58ae.tar.gz
Libft-671a58519ef6207b54947ff70eea497ff7eb58ae.zip
Restructure project layout and clean up test suite
Move sources to src/, header to inc/, and tests to tests/src/. Update Makefiles and .gitignore for the new layout. Refactor test harness: add crash-wrapper macros (_S_CRASH, _S_CRASH_I, _S_CRASH_V, _S_CRASH_BUF) replacing 58 hand-written wrappers, add shared _s_test_int_range helper eliminating duplicate _s_test_func, add _S_RAND_ITERS constant, move srand() to main() in all test binaries, and add Doxygen comments to test_utils.h.
Diffstat (limited to 'tests/test_atoi.c')
-rw-r--r--tests/test_atoi.c58
1 files changed, 0 insertions, 58 deletions
diff --git a/tests/test_atoi.c b/tests/test_atoi.c
deleted file mode 100644
index 196a081..0000000
--- a/tests/test_atoi.c
+++ /dev/null
@@ -1,58 +0,0 @@
-#include "../libft.h"
-#include "test_utils.h"
-#include <limits.h>
-
-static void
-_s_ft_atoi_null (void)
-{
- _s_sink_i = ft_atoi (NULL);
-}
-static void
-_s_libc_atoi_null (void)
-{
- _s_sink_i = atoi (NULL);
-}
-
-int
-main (void)
-{
- int i;
- char buf[64];
- char label[64];
-
- printf ("=== ft_atoi ===\n");
-
- /* NULL */
- _s_check_both_crash ("atoi NULL", _s_ft_atoi_null, _s_libc_atoi_null);
-
- /* edge cases */
- _s_check_eq_int ("zero", ft_atoi ("0"), atoi ("0"));
- _s_check_eq_int ("INT_MAX", ft_atoi ("2147483647"), atoi ("2147483647"));
- _s_check_eq_int ("INT_MIN", ft_atoi ("-2147483648"), atoi ("-2147483648"));
- _s_check_eq_int ("negative", ft_atoi ("-42"), atoi ("-42"));
- _s_check_eq_int ("explicit +", ft_atoi ("+42"), atoi ("+42"));
- _s_check_eq_int ("leading spaces", ft_atoi (" 42"), atoi (" 42"));
- _s_check_eq_int ("leading tabs", ft_atoi ("\t\n\v\f\r 42"),
- atoi ("\t\n\v\f\r 42"));
- _s_check_eq_int ("trailing chars", ft_atoi ("42abc"), atoi ("42abc"));
- _s_check_eq_int ("empty string", ft_atoi (""), atoi (""));
- _s_check_eq_int ("only spaces", ft_atoi (" "), atoi (" "));
- _s_check_eq_int ("only sign", ft_atoi ("-"), atoi ("-"));
- _s_check_eq_int ("sign then space", ft_atoi ("- 42"), atoi ("- 42"));
- _s_check_eq_int ("double sign", ft_atoi ("--42"), atoi ("--42"));
- _s_check_eq_int ("space between", ft_atoi ("4 2"), atoi ("4 2"));
- _s_check_eq_int ("leading zeros", ft_atoi ("00042"), atoi ("00042"));
-
- /* randomized */
- srand (time (NULL));
- for (i = 0; i < 50; i++)
- {
- int v = rand () - RAND_MAX / 2;
- snprintf (buf, sizeof (buf), "%d", v);
- snprintf (label, sizeof (label), "random %s", buf);
- _s_check_eq_int (label, ft_atoi (buf), atoi (buf));
- }
-
- _s_print_results ();
- return (_s_fail != 0);
-}