summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-01-03 17:00:19 -0700
committermo khan <mo@mokhan.ca>2015-01-03 17:00:19 -0700
commit88caf2ed9e2986b358e9cabeaee271b7357626d9 (patch)
treef083b9766b567fea2351b57b96ccf404989a62da
parente81d003ad7987389ad00897d672be873fe14bb06 (diff)
extract test runner into a separate file.
-rw-r--r--Makefile5
-rw-r--r--test/main.c9
-rw-r--r--test/main.h9
-rw-r--r--test/world_test.c14
4 files changed, 25 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index e56c926..3a57f35 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
SHELL=/bin/sh
CFLAGS=-Wall -g -std=c99 -Isrc
objects=cell.o world.o
-test_objects=world_test.o
+test_objects=world_test.o test_main.o
exe=./bin/game_of_life
test_exe=./bin/game_of_life_test
@@ -27,3 +27,6 @@ world.o: src/world.c src/world.h
world_test.o: test/world_test.c src/world.h
$(CC) $(CFLAGS) -c test/world_test.c
+
+test_main.o: test/main.c test/main.h
+ $(CC) $(CFLAGS) -c test/main.c -o test_main.o
diff --git a/test/main.c b/test/main.c
new file mode 100644
index 0000000..6753944
--- /dev/null
+++ b/test/main.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include "main.h"
+
+int main()
+{
+ world_tests();
+ printf("\nOK\n");
+ return 0;
+}
diff --git a/test/main.h b/test/main.h
new file mode 100644
index 0000000..8952a97
--- /dev/null
+++ b/test/main.h
@@ -0,0 +1,9 @@
+#define run_test(function_name)\
+ printf("%s\n", #function_name);\
+function_name();
+
+#include <assert.h>
+
+#include "world.h"
+
+void world_tests();
diff --git a/test/world_test.c b/test/world_test.c
index de055e3..a8f550d 100644
--- a/test/world_test.c
+++ b/test/world_test.c
@@ -1,11 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <assert.h>
-#include "world.h"
-
-#define run_test(function_name)\
- printf("%s\n", #function_name);\
-function_name();
+#include "main.h"
void test_world_create() {
int width = 3;
@@ -112,8 +107,7 @@ void it_returns_the_correct_number_of_living_neighbors() {
assert(world_neighbours(world, 8) == 3);
}
-int main()
-{
+void world_tests() {
run_test(test_world_create);
run_test(test_world_create_should_create_all_cells);
run_test(any_live_cell_with_fewer_than_two_live_neighbours_dies_as_if_caused_by_under_population);
@@ -122,7 +116,5 @@ int main()
run_test(any_live_cell_with_more_than_three_live_neighbours_dies_as_if_by_overcrowding);
run_test(any_dead_cell_with_exactly_three_live_neighbours_becomes_a_live_cell_as_if_by_reproduction);
run_test(it_returns_the_correct_number_of_living_neighbors);
-
- printf("\nOK\n");
- return 0;
}
+