Test Case Development Macros

Test case development for this course will make use of the following macros. Though these are macros, you can treat them much like you would a function (there are important differences, but that's a topic for later discussion).

You can download the header file for these test macros from here (checkit.h).

These macros are non-standard. You will not find discussion of them in the book or on any C site. They serve to simplify the creation of test cases in 101. You may continue to use them after 101, but in time you will develop different methods for unit testing or use tools provided by your development environment.

Each macro is used to develop unit tests of expressions that evaluate to the specified types (integer, double, char, or string). Each macro requires two arguments; the first is the expression to evaluate and the second is the expected correct result.

checkit_int(expression,expected)

For example, one test case might be checkit_int(square(3), 9);. When this test case is executed, the result of square(3) will be compared against the expected result of 9 and either success or failure will be reported.

checkit_double(expression,expected)

For example, one test case might be checkit_double(sqrt(9.0), 3.0);. When this test case is executed, the result of sqrt(9.0) will be compared against the expected result of 3.0 and either success or failure will be reported. Since double values cannot be accurately compared for equality, this test macro checks that the result and expected value are within an epsilon.

checkit_boolean(expression,expected)

For example, one test case might be checkit_boolean(1 > 2, 0);. When this test case is executed, the result of 1 > 2 will be compared against the expected result of 0 (i.e., false) and either success (in this case) or failure will be reported.

checkit_char(expression,expected)

For example, one test case might be checkit_char(str[0], 'a');. When this test case is executed, the result of str[0] will be compared against the expected result of 'a' and either success or failure will be reported.

checkit_string(expression,expected)

For example, one test case might be checkit_string(substring("abcd", 2), "ab");. When this test case is executed, the result of substring("abcd", 2) will be compared against the expected result of "ab" and either success or failure will be reported. This macro uses the standard strcmp function for string comparisons.