Commit 5eca8ef

mo k <mo@mokhan.ca>
2012-02-18 17:47:43
add first unit test.
1 parent 63b1e6e
Changed files (2)
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;
 }
practice
Binary file