#include "../strutil.h" #include #include static int fails; static void check_rev(const char *in, const char *want) { char buf[64]; snprintf(buf, sizeof(buf), "%s", in); str_reverse(buf); if (strcmp(buf, want) != 0) { printf("FAIL str_reverse(\"%s\") = \"%s\", want \"%s\"\n", in, buf, want); fails++; } } static void check_vowels(const char *in, int want) { int got = count_vowels(in); if (got != want) { printf("FAIL count_vowels(\"%s\") = %d, want %d\n", in, got, want); fails++; } } int main(void) { check_rev("abc", "cba"); check_rev("ab", "ba"); check_rev("", ""); check_vowels("education", 5); check_vowels("RHYTHM", 0); check_vowels("Queue", 4); if (fails) { printf("%d test(s) failed\n", fails); return 1; } printf("all tests passed\n"); return 0; }