alelievr / libft-unit-test

457 stars 88 forks source link

strcmp test issues? #32

Closed TRON-N closed 7 years ago

TRON-N commented 7 years ago

I'm not sure if this is an issue, but I noticed that the tests seem to expect ft_strcmp to exactly match the values returned by strcmp. But according to the man pages, and what I can tell from the internet, only the sign characteristics are defined, and not the actual return values of strcmp. Meaning that if s1[i] is larger than s2[i] the return should be positive, if they're equal the return should be 0, and if s1[i] is smaller than s2[i] the return should be negative. Now my function shows the correct sign behavior, but it does not equal strcmp's return values. I suppose my question is am I at fault, or is the test being unreasonable?

Could the fact that I'm using the libft-unit-test on ubuntu have an impact on anything?

alelievr commented 7 years ago

No, the strcmp tests does not expect exactly the same result from both functions. After the comparison, i have the REG() macro which evaluate the result of strcmp and ft_strcmp and "normalize" it. If the return value is > 0 REG return 1, if it is < 0 REG return -1 and if the return is 0 REG(0) is 0.

from the test_functions.c:

char    *s1 = "AAAAAAAAAB";
char    *s2 = "AAAAAAAAAC";

int     i1 = REG(strcmp(s1, s2));
int     i2 = REG(ft_strcmp(s1, s2));
if (i1 == i2)
    exit(TEST_SUCCESS);
SET_DIFF_INT(i1, i2);
exit(TEST_FAILED);

and REG:

#define     REG(x)      ((x > 0) ? 1 : ((x < 0) ? -1 : 0))

(and it's the same thing for strncmp).