Repository: bsatrom/py-conway

Issue:
make sure that the provided beacon only contains ones and zeroes

Discussion:

Patch:
diff --git a/conway/game.py b/conway/game.py
index d147be5..6d2b56e 100644
--- a/conway/game.py
+++ b/conway/game.py
@@ -42,6 +42,8 @@ class Game:
                 raise InitError("Please make sure that the seed matches \
                                  the provided width and height values.")
 
+            self._scan_seed(seed)
+
             self.seed = seed
             self.live_cells = self._count_live_cells(self.seed)
 
@@ -68,6 +70,17 @@ class Game:
         dim_one = [0 for row in range(rows)]
         return [dim_one[:] for col in range(cols)]
 
+    def _scan_seed(self, seed: list):
+        """
+        Scans each cell in a seed to make sure that only valid data (0, 1)
+        is present. Throws an InitError exception, if not.
+        """
+        for row in seed:
+            for item in row:
+                if item != 0 and item != 1:
+                    raise InitError("Game seed can only contain 0s \
+                                 and 1s.")
+
     def _num_neighbors(self, row: int, column: int) -> int:
         """
         Determine the number of neighbors to a given cell that


Test patch:
diff --git a/tests/tests.py b/tests/tests.py
index 548e82f..60bbf02 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -255,3 +255,28 @@ class TestConway():
         test_game.stop()
 
         assert test_game.state, GameState.FINISHED
+
+    def test_ensure_that_seed_includes_valid_data(self):
+        seed = [['a', 0, 0, 0],
+                [0, 2, 1, 0],
+                [0, 1, 1, 0],
+                [0, 0, 0, -1]]
+
+        with pytest.raises(InitError):
+            Game(4, 4, seed)
+
+        seed = [[0, 0, 0, 0],
+                [0, 2, 1, 0],
+                [0, 1, 1, 0],
+                [0, 0, 0, -1]]
+
+        with pytest.raises(InitError):
+            Game(4, 4, seed)
+
+        seed = [[0, 0, 0, 0],
+                [0, 0, 1, 0],
+                [0, 1, 1, 0],
+                [0, 0, 0, -1]]
+
+        with pytest.raises(InitError):
+            Game(4, 4, seed)