Commit 7c300d9
Changed files (4)
bin/test_game_of_life
Binary file
src/world.c
@@ -13,6 +13,10 @@ Cell* cell_create(int number_of_cells) {
return cells;
}
+int world_number_of_cells(World *world) {
+ return world->width * world->height;
+}
+
World *world_create(int width, int height) {
int number_of_cells = width*height;
World *world = (World *)malloc(sizeof(World));
@@ -23,3 +27,11 @@ World *world_create(int width, int height) {
world->cells = cell_create(number_of_cells);
return world;
}
+
+World* world_evolve(World *world) {
+ int number_of_cells = world_number_of_cells(world);
+ for (int i = 0; i < number_of_cells; i++) {
+ world->cells[sizeof(Cell) * i].alive = false;
+ }
+ return world;
+}
src/world_test.c
@@ -21,10 +21,23 @@ void test_world_create_should_create_all_cells(){
assert(false == world->cells[0].alive);
}
+void any_live_cell_with_fewer_than_two_live_neighbours_dies_as_if_caused_by_under_population() {
+ /*{ 'x', ' ', ' ' },*/
+ /*{ ' ', ' ', ' ' },*/
+ /*{ ' ', ' ', ' ' },*/
+ World *world = world_create(3, 3);
+ world->cells[0].alive = false;
+
+ world_evolve(world);
+ assert(false == world->cells[0].alive);
+ assert(false == world->cells[8].alive);
+}
+
int main()
{
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);
printf("\nOK\n");
return 0;
}
.gitignore
@@ -1,4 +1,3 @@
*.out
*.dSYM
-gol
-gol_test
+bin