diff options
| author | mo k <mo@mokhan.ca> | 2012-02-18 10:47:43 -0700 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-02-18 10:47:43 -0700 |
| commit | 5eca8effb10dc1823bd675aefa0e3edf26cf994a (patch) | |
| tree | 2daabedf63e60e4179fc7d8c198d63c53cdf987e /main.c | |
| parent | 63b1e6e93ad99095883aa02be2350af19106e680 (diff) | |
add first unit test.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -3,14 +3,28 @@ #include <string.h> #include "reverse.h" -int main(int argc, const char *argv[]) +int assert_equals(char *actual, char *expected) { - char input[128]; + int ret; + ret = strcmp(actual, expected); + if(ret != 0){ + printf("FAIL! actual: '%s', expected: '%s'", actual, expected); + } else { + printf("PASS! actual: '%s', expected: '%s'", actual, expected); + } - printf("enter a string to reverse: "); - gets(input); - reverse(input); - printf("%s", input); + return ret == 0?1:0; +} +void test_string_reversal() +{ + char input[32]; + strcpy( input, "tell The Truth"); + reverse(input); + assert_equals(input, "hturT ehT llet"); +} - return 0; +int main(int argc, const char *argv[]) +{ + test_string_reversal(); + return 0; } |
