/** * string-swap-utests: Unit tests of string-swap. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include // For printf #include // For strcpy #include "string-utils.h" // For string_swap #include "utest.h" // For CHECK_STRING // +---------+-------------------------------------------------------- // | Helpers | // +---------+ /** * Given an array of strings, make sure that every i/j swap * works correctly. */ void test_swap (char *strings[], int len) { char *original[len]; int i; int j; // Make a copy of the array so that we have something to compare it to for (i = 0; i < len; i++) original[i] = strings[i]; // Do every i/j pair for (i = 0; i < len; i++) { } // for } // test_swap // +------+----------------------------------------------------------- // | Main | // +------+ int main () { // A few simple strings test_swap ("abcde", "edcba"); test_swap ("madam im adam", "mada mi madam"); // A variety of sizes. (swap might have problems on some sizes). // Note: These should be generated automatically, but I'm lazy. test_swap ("", ""); test_swap ("z", "z"); test_swap ("yz", "zy"); test_swap ("xyz", "zyx"); test_swap ("wxyz", "zyxw"); test_swap ("vwxyz", "zyxwv"); test_swap ("uvwxyz", "zyxwvu"); test_swap ("tuvwxyz", "zyxwvut"); test_swap ("stuvwxyz", "zyxwvuts"); test_swap ("rstuvwxyz", "zyxwvutsr"); if (! errors) printf ("All tests passed!\n"); else printf ("%d errors encountered\n", errors); return errors; } // main