2019-02-23 15:20:48 +00:00
|
|
|
"""
|
|
|
|
Copyright 2019 Richard Feistenauer
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
"""
|
|
|
|
|
2019-01-31 15:15:59 +00:00
|
|
|
import sys
|
2019-02-23 15:20:48 +00:00
|
|
|
sys.path.append('../..')
|
2019-01-31 15:15:59 +00:00
|
|
|
|
2019-02-23 15:43:36 +00:00
|
|
|
from cellular_automaton.cellular_automaton import cell_state as cell_state
|
2019-01-31 15:15:59 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
class TestCellState(unittest.TestCase):
|
2019-02-15 18:33:15 +00:00
|
|
|
def setUp(self):
|
2019-02-23 15:20:48 +00:00
|
|
|
self.cell_state = cell_state.SynchronousCellState(initial_state=(0,), draw_first_state=False)
|
2019-01-31 15:15:59 +00:00
|
|
|
|
2019-02-02 08:11:48 +00:00
|
|
|
def test_get_state_with_overflow(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
self.cell_state.set_state_of_evolution_step(new_state=(1,), evolution_step=0)
|
|
|
|
self.assertEqual(tuple(self.cell_state.get_state_of_evolution_step(2)), (1,))
|
2019-02-02 08:11:48 +00:00
|
|
|
|
|
|
|
def test_set_state_with_overflow(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
self.cell_state.set_state_of_evolution_step(new_state=(1,), evolution_step=3)
|
|
|
|
self.assertEqual(tuple(self.cell_state.get_state_of_evolution_step(1)), (1,))
|
2019-02-02 08:11:48 +00:00
|
|
|
|
|
|
|
def test_set_state_does_not_effect_all_slots(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
self.cell_state.set_state_of_evolution_step(new_state=(1,), evolution_step=0)
|
|
|
|
self.assertEqual(tuple(self.cell_state.get_state_of_evolution_step(1)), (0,))
|
2019-01-31 15:15:59 +00:00
|
|
|
|
2019-02-03 16:17:57 +00:00
|
|
|
def test_redraw_state_on_change(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
self.cell_state.set_state_of_evolution_step(new_state=(1,), evolution_step=0)
|
2019-02-15 18:33:15 +00:00
|
|
|
self.assertTrue(self.cell_state.is_set_for_redraw())
|
2019-02-03 16:17:57 +00:00
|
|
|
|
|
|
|
def test_redraw_state_on_nochange(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
self.cell_state.set_state_of_evolution_step(new_state=(0,), evolution_step=0)
|
2019-02-15 18:33:15 +00:00
|
|
|
self.assertFalse(self.cell_state.is_set_for_redraw())
|
2019-02-03 16:17:57 +00:00
|
|
|
|
|
|
|
def test_active_state_after_set(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
self.cell_state.set_state_of_evolution_step(new_state=(1,), evolution_step=0)
|
2019-02-15 18:33:15 +00:00
|
|
|
self.assertFalse(self.cell_state.is_active(0))
|
|
|
|
self.assertFalse(self.cell_state.is_active(1))
|
|
|
|
|
2019-02-16 17:05:26 +00:00
|
|
|
def test_set_active_for_next_evolution_step(self):
|
|
|
|
self.cell_state.set_state_of_evolution_step(new_state=(1,), evolution_step=0)
|
|
|
|
self.cell_state.set_active_for_next_evolution_step(0)
|
2019-02-15 18:33:15 +00:00
|
|
|
self.assertFalse(self.cell_state.is_active(0))
|
|
|
|
self.assertTrue(self.cell_state.is_active(1))
|
|
|
|
|
|
|
|
def test_new_state_length(self):
|
|
|
|
self.assertRaises(IndexError, self.__set_state_with_new_length)
|
|
|
|
|
|
|
|
def __set_state_with_new_length(self):
|
2019-02-16 17:05:26 +00:00
|
|
|
return self.cell_state.set_state_of_evolution_step(new_state=(1, 1), evolution_step=0)
|
2019-02-15 18:33:15 +00:00
|
|
|
|
|
|
|
def test_redraw_flag(self):
|
2019-02-23 15:20:48 +00:00
|
|
|
self.cell_state = cell_state.SynchronousCellState(initial_state=(0,), draw_first_state=True)
|
2019-02-15 18:33:15 +00:00
|
|
|
self.assertTrue(self.cell_state.is_set_for_redraw())
|
|
|
|
self.cell_state.was_redrawn()
|
|
|
|
self.assertFalse(self.cell_state.is_set_for_redraw())
|
2019-02-03 16:17:57 +00:00
|
|
|
|
2019-01-31 15:15:59 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|