Commit 88caf2e
Changed files (4)
test
test/main.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include "main.h"
+
+int main()
+{
+ world_tests();
+ printf("\nOK\n");
+ return 0;
+}
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();
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;
}
+
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