From 1a96e90116f4dbbb70b11f6d2ad4e9569e6b7481 Mon Sep 17 00:00:00 2001 From: Richard Feistenauer Date: Sun, 14 Apr 2019 11:18:39 +0200 Subject: [PATCH] fixed ignore edge cells only ignoring corners --- cellular_automaton/neighborhood.py | 2 +- test/test_neighborhood.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cellular_automaton/neighborhood.py b/cellular_automaton/neighborhood.py index 64f1245..ee9ee08 100644 --- a/cellular_automaton/neighborhood.py +++ b/cellular_automaton/neighborhood.py @@ -64,7 +64,7 @@ class Neighborhood: return self.__edge_rule == EdgeRule.IGNORE_EDGE_CELLS and self.__is_coordinate_on_an_edge(coordinate) def __is_coordinate_on_an_edge(self, coordinate): - return all(0 == ci or ci == di-1 for ci, di in zip(coordinate, self.__grid_dimensions)) + return any(0 == ci or ci == di-1 for ci, di in zip(coordinate, self.__grid_dimensions)) def __apply_edge_overflow(self, n): return list(map(lambda ni, di: (ni + di) % di, n, self.__grid_dimensions)) diff --git a/test/test_neighborhood.py b/test/test_neighborhood.py index 2d7488c..edcda04 100644 --- a/test/test_neighborhood.py +++ b/test/test_neighborhood.py @@ -35,16 +35,19 @@ class TestNeighborhood(unittest.TestCase): def test_ignore_missing_neighbors(self): neighborhood = csn.MooreNeighborhood(csn.EdgeRule.IGNORE_MISSING_NEIGHBORS_OF_EDGE_CELLS) n00 = [[0, 0], [[1, 0], [0, 1], [1, 1]]] + n01 = [[0, 1], [[0, 0], [1, 0], [1, 1], [0, 2], [1, 2]]] n11 = [[1, 1], [[0, 0], [1, 0], [2, 0], [0, 1], [2, 1], [0, 2], [1, 2], [2, 2]]] n22 = [[2, 2], [[1, 1], [2, 1], [1, 2]]] - self.assertTrue(self.check_neighbors(neighborhood, [n00, n11, n22])) + self.assertTrue(self.check_neighbors(neighborhood, [n00, n01, n11, n22])) def test_ignore_edge_cells(self): neighborhood = csn.MooreNeighborhood(csn.EdgeRule.IGNORE_EDGE_CELLS) n00 = [[0, 0], []] + n01 = [[0, 1], []] + n20 = [[2, 0], []] n11 = [[1, 1], [[0, 0], [1, 0], [2, 0], [0, 1], [2, 1], [0, 2], [1, 2], [2, 2]]] n22 = [[2, 2], []] - self.assertTrue(self.check_neighbors(neighborhood, [n00, n11, n22])) + self.assertTrue(self.check_neighbors(neighborhood, [n00, n01, n20, n11, n22])) def test_cyclic_dimensions(self): neighborhood = csn.MooreNeighborhood(csn.EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS)