2019-02-02 08:11:48 +00:00
|
|
|
import sys
|
|
|
|
sys.path.append('../src')
|
|
|
|
|
2019-02-17 10:11:27 +00:00
|
|
|
from cellular_automaton.cellular_automaton import *
|
2019-02-02 08:11:48 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
2019-02-09 18:06:18 +00:00
|
|
|
class TestState(CellState):
|
2019-02-03 16:17:57 +00:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
|
2019-02-02 08:11:48 +00:00
|
|
|
class TestCellState(unittest.TestCase):
|
2019-02-03 16:17:57 +00:00
|
|
|
def setUp(self):
|
2019-02-15 19:02:57 +00:00
|
|
|
self.cell = Cell(TestState)
|
2019-02-16 17:05:26 +00:00
|
|
|
self.neighbors = [TestState() for x in range(5)]
|
|
|
|
for neighbor in self.neighbors:
|
|
|
|
neighbor.set_state_of_evolution_step((0, ), 0)
|
|
|
|
self.cell.neighbor_states = self.neighbors
|
2019-02-03 16:17:57 +00:00
|
|
|
|
2019-02-16 17:05:26 +00:00
|
|
|
def cell_and_neighbors_active(self, evolution_step):
|
|
|
|
self.neighbors.append(self.cell.state)
|
2019-02-03 16:17:57 +00:00
|
|
|
all_active = True
|
2019-02-16 17:05:26 +00:00
|
|
|
for state in self.neighbors:
|
|
|
|
if not state.is_active(evolution_step):
|
2019-02-03 16:17:57 +00:00
|
|
|
all_active = False
|
|
|
|
return all_active
|
|
|
|
|
|
|
|
def test_evolve_activation(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
self.cell.evolve_if_ready((lambda a, b: (1,)), 0)
|
|
|
|
all_active = self.cell_and_neighbors_active(1)
|
2019-02-03 16:17:57 +00:00
|
|
|
self.assertTrue(all_active)
|
|
|
|
|
|
|
|
def test_evolve_activation_on_no_change(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
self.cell.evolve_if_ready((lambda a, b: (0,)), 0)
|
|
|
|
all_active = self.cell_and_neighbors_active(1)
|
2019-02-03 16:17:57 +00:00
|
|
|
self.assertFalse(all_active)
|
2019-02-02 08:11:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|