I'm currently trying to test a strcat()
function that I wrote myself. Instead of printing the outputs and checking them line by line manually, I've decided to use assert from assert.h. The problem is that assert is showing errors even though the outputs look totally fine. The following is my code:
void mystrcat_test()
{
char str[BUFSIZ];
assert(strcmp(str, ""));
mystrcat(str, "hello");
assert(strcmo(str, "hello"));
}
strcmp
returns 0 if both strings are same. assert
takes 0 (false) as an indication that the test failed and will report error. So the test should be:
assert(strcmp(str, "") == 0);
strcmp
returns 0 when strings match, so your tests need to be inverted, e.g.
assert(strcmp(str, "hello") == 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With