added test for cell state and fixed wront initial state
This commit is contained in:
parent
7b37953903
commit
2f1bdba023
@ -5,7 +5,7 @@ class CellState:
|
|||||||
"""
|
"""
|
||||||
def __init__(self, initial_state, state_save_slot_count=2):
|
def __init__(self, initial_state, state_save_slot_count=2):
|
||||||
self._state_save_slot_count = state_save_slot_count
|
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):
|
def set_status_of_iteration(self, new_status, iteration):
|
||||||
""" Will set the new status for the iteration modulo number of saved states.
|
""" Will set the new status for the iteration modulo number of saved states.
|
||||||
|
27
test/test_cell_state.py
Normal file
27
test/test_cell_state.py
Normal 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()
|
@ -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()
|
|
Loading…
Reference in New Issue
Block a user