/// @file /// @brief Task3: tests #include "task3.h" // struct StringStats, task3_stringstats #include // assert #include // printf int main() { { // testing 'task3_stringstats' (empty string) const char str[] = ""; struct StringStats res = task3_stringstats(str); assert(res.lines == 0); assert(res.words == 0); } { // testing 'task3_stringstats' (one line) const char str[] = "this is one line\n"; struct StringStats res = task3_stringstats(str); printf("stats: %u %u\n", res.lines, res.words); assert(res.lines == 1); assert(res.words == 4); } { // testing 'task3_stringstats' (two lines) const char str[] = "this is \ntwo lines.\n"; struct StringStats res = task3_stringstats(str); printf("stats: %u %u\n", res.lines, res.words); assert(res.lines == 2); assert(res.words == 4); } { // testing 'task3_stringstats' (two line leading spaces) const char str[] = " this is \n two lines.\n"; struct StringStats res = task3_stringstats(str); printf("stats: %u %u\n", res.lines, res.words); assert(res.lines == 2); assert(res.words == 4); } { // testing 'task3_stringstats' (multiple lines) const char str[] = "this is \nmore than\ntwo lines.\n"; struct StringStats res = task3_stringstats(str); printf("stats: %u %u\n", res.lines, res.words); assert(res.lines == 3); assert(res.words == 6); } { // testing 'task3_stringstats' (multiple lines, empty lines in between, leading spaces, trailing spaces) const char str[] = " this is \n more than\n two lines \n including \n\n empty lines \n and spaces.\n"; // const char str[] = " \n\n "; struct StringStats res = task3_stringstats(str); printf("stats: %u %u\n", res.lines, res.words); assert(res.lines == 7); assert(res.words == 11); } printf("task3.test.c: all asserts passed\n"); return 0; }