added test for cell state and fixed wront initial state

This commit is contained in:
Richard Feistenauer 2019-01-31 16:15:59 +01:00
parent 7b37953903
commit 2f1bdba023
3 changed files with 28 additions and 21 deletions

View File

@ -5,7 +5,7 @@ class CellState:
"""
def __init__(self, initial_state, state_save_slot_count=2):
self._state_save_slot_count = state_save_slot_count
self._state_slots = [[initial_state]] * state_save_slot_count
self._state_slots = [initial_state] * state_save_slot_count
def set_status_of_iteration(self, new_status, iteration):
""" Will set the new status for the iteration modulo number of saved states.

27
test/test_cell_state.py Normal file
View File

@ -0,0 +1,27 @@
import sys
sys.path.append('../src')
import cellular_automaton.ca_cell_state as cs
import unittest
class TestCellState(unittest.TestCase):
def test_get_state_of_iteration(self):
cell_state = cs.CellState(0, state_save_slot_count=3)
cell_state.set_status_of_iteration(1, 0)
self.assertEqual(cell_state.get_status_of_iteration(3), 1)
def test_set_state_applies_overflow(self):
cell_state = cs.CellState(0, state_save_slot_count=4)
cell_state.set_status_of_iteration(1, 4)
self.assertEqual(cell_state.get_status_of_iteration(0), 1)
def test_set_state_only_applies_to_iteration_slot(self):
cell_state = cs.CellState(0, state_save_slot_count=2)
cell_state.set_status_of_iteration(1, 0)
self.assertEqual(cell_state.get_status_of_iteration(1), 0)
if __name__ == '__main__':
unittest.main()

View File

@ -1,20 +0,0 @@
import sys
sys.path.append('../src')
import cellular_automaton.ca_cell_state as cs
import unittest
class TestState(unittest.TestCase):
def test_state_slots(self):
cell_state = cs.CellState([0])
cell_state.set_status_of_iteration([1], 0)
cell_state.set_status_of_iteration([2], 1)
cell_state.set_status_of_iteration([3], 2)
self.assertEqual(cell_state.get_status_of_iteration(0), [3])
if __name__ == '__main__':
unittest.main()