alelievr / libft-unit-test

455 stars 88 forks source link

Missing tests for ft_putnbr and potentially for ft_atoi #102

Closed Blenderwizard closed 1 year ago

Blenderwizard commented 3 years ago

Info

  1. The tests done for _ftputnbr do not consider the case where 0 is the value passed to the function.
  2. There is also no test for _ftatoi that tests "0", "-0", or "+0" while _ftitoa has one of these tests.

Description

_ftputnbr

Explanation

Below is an example implementation that does not perform correctly when inputted 0 but passes all tests.

// Example implementation 
void    ft_putnbr(int n)
{
    if (n == -2147483648)
        ft_putstr("-2147483648");
    else if (n < 0)
    {
        ft_putchar('-');
        n *= -1;
    }
    if (n > 0)
    {
        ft_putnbr(n/10);
        ft_putchar((char)((n % 10) + 48));
    }
}

Expected Output -> 0 My Output -> EMPTY Test Results -> All Green

Fix

Implement a test case for 0.

_ftatoi

Explanation & Fix

_ftatoi does not have a test case for "0", "-0", "+0". At least one test case should be added for safety and to match _ftitoa that does one case for -0.

github-actions[bot] commented 2 years ago

Hello! Thanks for contributing to the libft unit test.

Note that this repository is not maintained by the owner anymore, instead there is a bot that will automatically merge any reviewed pull requests. If you feel like it, here are some links that can help you submiting a change in the code base::