Adds setter for automaton cells
This commit is contained in:
parent
1ed82116ce
commit
03601c2060
@ -89,7 +89,14 @@ class CellularAutomaton(CellularAutomatonCreator, abc.ABC):
|
|||||||
def get_cells(self):
|
def get_cells(self):
|
||||||
return self._current_state
|
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):
|
def get_evolution_step(self):
|
||||||
return self._evolution_step
|
return self._evolution_step
|
||||||
|
@ -34,17 +34,14 @@ class TAutomaton(ca.CellularAutomaton):
|
|||||||
NEIGHBORHOOD = ca.MooreNeighborhood(ca.EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS)
|
NEIGHBORHOOD = ca.MooreNeighborhood(ca.EdgeRule.FIRST_AND_LAST_CELL_OF_DIMENSION_ARE_NEIGHBORS)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
def test_process_evolution_steps():
|
||||||
def automaton():
|
automaton = TAutomaton(NEIGHBORHOOD, [3, 3])
|
||||||
return TAutomaton(NEIGHBORHOOD, [3, 3])
|
|
||||||
|
|
||||||
|
|
||||||
def test_process_evolution_steps(automaton):
|
|
||||||
automaton.evolve(5)
|
automaton.evolve(5)
|
||||||
assert automaton.evolution_step == 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)
|
automaton.evolve(5)
|
||||||
assert automaton.cells[(1, 1)].state[0] == 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 = TAutomaton(ca.MooreNeighborhood(), dimension=[3] * dimensions)
|
||||||
automaton.evolve()
|
automaton.evolve()
|
||||||
assert automaton.cells[(1, ) * dimensions].state[0] == 1
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user