diff --git a/src/cellular_automaton/ca_cell_state.py b/src/cellular_automaton/ca_cell_state.py index 68ff325..b01ceae 100644 --- a/src/cellular_automaton/ca_cell_state.py +++ b/src/cellular_automaton/ca_cell_state.py @@ -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. diff --git a/test/test_cell_state.py b/test/test_cell_state.py new file mode 100644 index 0000000..ea1d3ab --- /dev/null +++ b/test/test_cell_state.py @@ -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() diff --git a/test/test_state.py b/test/test_state.py deleted file mode 100644 index fababeb..0000000 --- a/test/test_state.py +++ /dev/null @@ -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()