Adds setter for automaton cells

This commit is contained in:
rfeistenauer 2020-10-22 15:33:13 +02:00
parent 1ed82116ce
commit 03601c2060
2 changed files with 20 additions and 8 deletions

View File

@ -89,7 +89,14 @@ class CellularAutomaton(CellularAutomatonCreator, abc.ABC):
def get_cells(self):
return self._current_state
cells = property(get_cells)
def set_cells(self, cells):
""" Sets the cell states both as current and next states """
for (coordinate, c_cell), n_cell in zip(self._current_state.items(), self._next_state.values()):
new_cell_state = cells[coordinate].state
c_cell.state = new_cell_state
n_cell.state = new_cell_state
cells = property(get_cells, set_cells)
def get_evolution_step(self):
return self._evolution_step

View File

@ -34,17 +34,14 @@ class TAutomaton(ca.CellularAutomaton):
NEIGHBORHOOD = ca.MooreNeighborhood(ca.EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS)
@pytest.fixture
def automaton():
return TAutomaton(NEIGHBORHOOD, [3, 3])
def test_process_evolution_steps(automaton):
def test_process_evolution_steps():
automaton = TAutomaton(NEIGHBORHOOD, [3, 3])
automaton.evolve(5)
assert automaton.evolution_step == 5
def test_process_evolution_calls(automaton):
def test_process_evolution_calls():
automaton = TAutomaton(NEIGHBORHOOD, [3, 3])
automaton.evolve(5)
assert automaton.cells[(1, 1)].state[0] == 5
@ -54,3 +51,11 @@ def test_dimensions(dimensions):
automaton = TAutomaton(ca.MooreNeighborhood(), dimension=[3] * dimensions)
automaton.evolve()
assert automaton.cells[(1, ) * dimensions].state[0] == 1
def test_process_evolution_calls():
automaton = TAutomaton(NEIGHBORHOOD, [3, 3])
automaton.evolve(5)
automaton2 = TAutomaton(NEIGHBORHOOD, [3, 3])
automaton2.cells = automaton.cells
assert automaton2.cells[(1, 1)].state[0] == 5