Commit c7bc275

mo khan <mo@mokhan.ca>
2014-12-30 14:54:20
remove old files.
1 parent 11da7d3
src/gol.c
@@ -1,53 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <math.h>
-#include <string.h>
-#include "gol.h"
-
-int alive(char value) { return value == ALIVE ? 1 : 0; };
-
-int west_of(int index) { return (index % WIDTH == 0) ?  index + (WIDTH-1) : index - 1; }
-int east_of(int index) { return (index % WIDTH == (WIDTH-1)) ? index - (WIDTH-1) : index + 1; }
-int north_of(int index) { return (index % WIDTH == index) ? NUMBER_OF_CELLS - WIDTH : index - WIDTH; }
-int south_of(int index) { 
-  return (index >= (NUMBER_OF_CELLS - WIDTH)) ? index - (NUMBER_OF_CELLS - HEIGHT) : index + WIDTH;
-}
-int north_west_of(int index) { return west_of(north_of(index)); }
-int north_east_of(int index) { return east_of(north_of(index)); }
-int south_west_of(int index) { return west_of(south_of(index)); }
-int south_east_of(int index) { return east_of(south_of(index)); }
-
-int living_neighbours_for(char* world, int index){
-  return alive(world[west_of(index)])
-    + alive(world[east_of(index)])
-    + alive(world[north_of(index)])
-    + alive(world[south_of(index)])
-    + alive(world[north_west_of(index)])
-    + alive(world[north_east_of(index)])
-    + alive(world[south_west_of(index)])
-    + alive(world[south_east_of(index)])
-    ;
-}
-
-char* evolve(char* world) {
-  char* new_world = malloc(sizeof(char) * NUMBER_OF_CELLS);
-  memset(new_world, 0, sizeof(char) * NUMBER_OF_CELLS);
-  for (int i = 0; i < NUMBER_OF_CELLS; i++) {
-    int neighbours = living_neighbours_for(world, i);
-    if (alive(world[i])) {
-      new_world[i] = (neighbours >= 2 && neighbours <= 3) ? ALIVE : DEAD;
-    } else {
-      new_world[i] = neighbours == 3 ? ALIVE : DEAD;
-    }
-  }
-  return new_world;
-}
-
-void display(char* world) {
-  for (int i = 0; i < NUMBER_OF_CELLS; i++) {
-    if (i % WIDTH == 0) { printf("\n"); }
-    printf("%c", world[i]);
-  }
-  printf("\n");
-}
src/gol.h
@@ -1,10 +0,0 @@
-static const char ALIVE='x';
-static const char DEAD=' ';
-
-extern int WIDTH;
-extern int HEIGHT;
-extern int NUMBER_OF_CELLS;
-
-int living_neighbours_for(char* world, int index);
-char* evolve(char* world);
-void display(char* world);
src/gol_test.c
@@ -1,120 +0,0 @@
-#include <stdio.h>
-#include "miniunit.h"
-#include "gol.h"
-
-int tests_run = 0;
-int WIDTH = 3;
-int HEIGHT = 3;
-int NUMBER_OF_CELLS;
-
-static char* test_foo() {
-  int foo = 7;
-  assert_equal(foo == 7, "error, foo != 7");
-  return 0;
-}
-
-static char* any_live_cell_with_fewer_than_two_live_neighbours_dies_as_if_caused_by_under_population() {
-  printf("TEST: %s\n", __func__);
-  char world[3][3] = {
-    { 'x', ' ', ' ' },
-    { ' ', ' ', ' ' },
-    { ' ', ' ', ' ' },
-  };
-  char* new_world = evolve(*world);
-  printf("%s\n", new_world);
-  assert_equal(new_world[0] == ' ', "should die because has 1 living neighbours");
-  assert_equal(new_world[8] == ' ', "should die because has 0 living neighbours");
-  return 0;
-}
-
-static char* any_live_cell_with_two_live_neighbours_lives_on_to_the_next_generation() {
-  printf("TEST: %s\n", __func__);
-  char world[3][3] = {
-    { 'x', 'x', 'x' },
-    { ' ', ' ', ' ' },
-    { ' ', ' ', ' ' },
-  };
-  char* new_world = evolve(*world);
-  assert_equal(new_world[1] == 'x', "should live because has 2 live neighbors");
-  return 0;
-}
-
-static char* any_live_cell_with_three_live_neighbours_lives_on_to_the_next_generation() {
-  printf("TEST: %s\n", __func__);
-  char world[3][3] = {
-    { 'x', ' ', 'x' },
-    { ' ', 'x', ' ' },
-    { ' ', ' ', ' ' },
-  };
-  char* new_world = evolve(*world);
-  assert_equal(new_world[1] == 'x', "lives because has 3 live neighbors");
-  return 0;
-}
-
-static char* any_live_cell_with_more_than_three_live_neighbours_dies_as_if_by_overcrowding() {
-  printf("TEST: %s\n", __func__);
-  char world[3][3] = {
-    { ' ', 'x', ' ' },
-    { 'x', 'x', 'x' },
-    { ' ', 'x', ' ' },
-  };
-  char* new_world = evolve(*world);
-  assert_equal(new_world[4] == ' ', "dies because has 4 neighbors");
-  return 0;
-}
-
-static char* any_dead_cell_with_exactly_three_live_neighbours_becomes_a_live_cell_as_if_by_reproduction(){
-  printf("TEST: %s\n", __func__);
-  char world[3][3] = {
-    { ' ', 'x', ' ' },
-    { 'x', ' ', 'x' },
-    { ' ', ' ', ' ' },
-  };
-  char* new_world = evolve(*world);
-  assert_equal(new_world[4] == 'x', "is born because has 3 live neighbors");
-  return 0;
-}
-
-static char* it_returns_the_correct_number_of_living_neighbors() {
-  printf("TEST: %s\n", __func__);
-  char world[3][3] = {
-    { 'x', ' ', 'x' },
-    { ' ', ' ', ' ' },
-    { 'x', ' ', 'x' },
-  };
-  assert_equal(living_neighbours_for(*world, 0) == 3, "0, 0 should return 3");
-  assert_equal(living_neighbours_for(*world, 1) == 4, "1, 0 should return 4");
-  assert_equal(living_neighbours_for(*world, 2) == 3, "2, 0 should return 3");
-  assert_equal(living_neighbours_for(*world, 3) == 4, "0, 1 should return 4");
-  assert_equal(living_neighbours_for(*world, 4) == 4, "1, 1 should return 4");
-  assert_equal(living_neighbours_for(*world, 5) == 4, "2, 1 should return 4");
-  assert_equal(living_neighbours_for(*world, 6) == 3, "0, 2 should return 3");
-  assert_equal(living_neighbours_for(*world, 7) == 4, "1, 2 should return 4");
-  assert_equal(living_neighbours_for(*world, 8) == 3, "2, 2 should return 3");
-  return 0;
-}
-
-static char* all_tests() {
-  run_test(test_foo);
-  run_test(it_returns_the_correct_number_of_living_neighbors);
-  run_test(any_live_cell_with_fewer_than_two_live_neighbours_dies_as_if_caused_by_under_population);
-  run_test(any_live_cell_with_two_live_neighbours_lives_on_to_the_next_generation);
-  run_test(any_live_cell_with_three_live_neighbours_lives_on_to_the_next_generation);
-  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);
-  return 0;
-}
-
-int main(int argc, char **argv) {
-  NUMBER_OF_CELLS=WIDTH*HEIGHT;
-
-  char *result = all_tests();
-  if (result != 0) {
-    printf("FAILED: %s\n", result);
-  }
-  else {
-    printf("ALL TESTS PASSED\n");
-  }
-  printf("Tests run: %d\n", tests_run);
-  return result != 0;
-}
src/miniunit.h
@@ -1,4 +0,0 @@
- #define assert_equal(test, message) do { if (!(test)) return message; } while (0)
- #define run_test(test) do { char *message = test(); tests_run++; \
-                                   if (message) return message; } while (0)
- extern int tests_run;