summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-02-18 10:47:43 -0700
committermo k <mo@mokhan.ca>2012-02-18 10:47:43 -0700
commit5eca8effb10dc1823bd675aefa0e3edf26cf994a (patch)
tree2daabedf63e60e4179fc7d8c198d63c53cdf987e /main.c
parent63b1e6e93ad99095883aa02be2350af19106e680 (diff)
add first unit test.
Diffstat (limited to 'main.c')
-rw-r--r--main.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/main.c b/main.c
index 5ac1b65..24ec67c 100644
--- a/main.c
+++ b/main.c
@@ -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;
}