Skip to content

Commit

Permalink
Update test_atoi.c (#2)
Browse files Browse the repository at this point in the history
Enhances the testing of the atoi implementation in the repository. While the current test suite checks the basic functionality of atoi, it does not verify that it handles overflow conditions correctly, which is an important aspect of the original atoi function.

To address this limitation, introduces additional test cases that specifically check for overflow scenarios, such as when the input string represents a value greater/less than LONG_MAX or less/greater than LONG_MIN. The tests are designed to ensure that the atoi implementation correctly handles these overflow cases by returning values that may include 0, 1, 2, -1, -2, or similar values, mirroring the behavior of the original atoi function in these scenarios.

Co-authored-by: kingcreek <[email protected]>
  • Loading branch information
Desoroxxx and kingcreek authored Oct 19, 2024
1 parent 1628e80 commit 85c3827
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/libft/fsoares/test_atoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ int test_atoi(void)
res = single_test_atoi(13, "1209") && res;
res = single_test_atoi(14, "12/3") && res;
res = single_test_atoi(15, "12;3") && res;
res = single_test_atoi(16, "92233720368547758070") && res;
res = single_test_atoi(17, "-92233720368547758080") && res;
res = single_test_atoi(18, "9223372036854775806") && res;
res = single_test_atoi(19, "-9223372036854775806") && res;
sprintf(buffer, "%i", INT_MAX);
res = single_test_atoi(16, buffer) && res;
res = single_test_atoi(20, buffer) && res;
sprintf(buffer, "%i", INT_MIN);
res = single_test_atoi(17, buffer) && res;
res = single_test_atoi(21, buffer) && res;

for (int i = 0; i <= 0xFF; i++) {
sprintf(buffer, "%c %i", i, i + 1);
Expand Down

0 comments on commit 85c3827

Please sign in to comment.