smaugmol@us-s2:~/D09T06_ID_1577487-1/src/s21_string$ cat s21_string_test.c
#include "s21_string.h"
void s21_strlen_test(void) {
const char *tests[] = {"Hello", "", "School 21"};
const size_t expected[] = {5, 0, 9};
const size_t count = sizeof(tests) / sizeof(tests[0]);
for (size_t i = 0; i < count; i++) {
size_t result = s21_strlen(tests[i]);
printf("Input: \"%s\", Output: %zu, Expected: %zu — %s\n", tests[i], result, expected[i],
result == expected[i] ? "SUCCESS" : "FAIL");
}
}
void s21_strcmp_test(void) {
const char *str1[] = {"abc", "abc", "abc", "", "a"};
const char *str2[] = {"abc", "abd", "abb", "", ""};
const int expected[] = {0, -1, 1, 0, 97};
const size_t count = sizeof(str1) / sizeof(str1[0]);
for (size_t i = 0; i < count; i++) {
int result = s21_strcmp(str1[i], str2[i]);
int success = (result == 0 && expected[i] == 0) || (result < 0 && expected[i] < 0) ||
(result > 0 && expected[i] > 0);
printf("Input: \"%s\", \"%s\", Output: %d, Expected sign: %d — %s\n", str1[i], str2[i], result,
expected[i], success ? "SUCCESS" : "FAIL");
}
}
int main(void) {
#ifdef TEST_STRLEN_ONLY
s21_strlen_test();
#elif defined(TEST_STRCMP_ONLY)
s21_strcmp_test();
#else
s21_strlen_test();
s21_strcmp_test();
#endif
return 0;
}