def setUp(self): self._default = ISolverState(num_nodes=4, num_time_steps=3) _initial = IStepState() _initial.solution.value = numpy.array([42.21]) _initial.solution.time_point = 0.1 self._default.initial = _initial
class ISolverStateTest(TestCase): def setUp(self): self._default = ISolverState(num_nodes=4, num_time_steps=3) _initial = IStepState() _initial.solution.value = numpy.array([42.21]) _initial.solution.time_point = 0.1 self._default.initial = _initial def test_initialized_without_states(self): self.assertIs(len(self._default), 0) def test_has_interval_dimension(self): self.assertEqual(self._default.delta_interval, 0.0) self._default.delta_interval = 1.0 self.assertEqual(self._default.delta_interval, 1.0) with self.assertRaises(ValueError): self._default.delta_interval = -0.1 def test_proceeds_infinitely(self): self.assertIs(len(self._default), 0) self._default.proceed() self.assertIs(len(self._default), 1) self.assertTrue(self._default.is_first_iteration) def test_has_accessors_for_number_time_steps_and_nodes(self): self.assertIs(self._default.num_nodes, 4) self.assertIs(self._default.num_time_steps, 3) def test_has_current_accessor(self): self.assertIsNone(self._default.current) self._default.proceed() self.assertIs(self._default.current, self._default[0]) def test_has_previous_accessor(self): self.assertIsNone(self._default.previous) self._default.proceed() self.assertIsNone(self._default.previous) self._default.proceed() self.assertIs(self._default.previous, self._default[0]) def test_has_first_and_last_accessor(self): self._default.proceed() has_first_and_last_accessor(self._default) def test_on_finalize_collect_solutions_and_finalize(self): self.assertFalse(self._default.finalized) self._default.finalize() self.assertTrue(self._default.finalized) self.setUp() self._default.proceed() self._default.finalize() def test_has_proxies_for_time_step_and_step(self): self._default.proceed() self._check_proxies() self._default.current_iteration.proceed() self._check_proxies() self._default.current_time_step.proceed() self._check_proxies() def test_has_aliases_for_state_accessors(self): self._check_iteration_aliases() self._default.proceed() self._check_iteration_aliases() def _check_proxies(self): self.assertIs(self._default.current_time_step, self._default.current_iteration.current_time_step) self.assertIs(self._default.current_time_step_index, self._default.current_iteration.current_time_step_index) self.assertIs(self._default.previous_time_step, self._default.current_iteration.previous_time_step) self.assertIs(self._default.next_time_step, self._default.current_iteration.next_time_step) self.assertIs(self._default.current_step, self._default.current_iteration.current_time_step.current_step) self.assertIs( self._default.current_step_index, self._default.current_iteration.current_time_step.current_step_index ) self.assertIs(self._default.previous_step, self._default.current_iteration.current_time_step.previous_step) self.assertIs(self._default.next_step, self._default.current_iteration.current_time_step.next_step) def _check_iteration_aliases(self): self.assertIs(self._default.current_iteration, self._default.current) self.assertIs(self._default.current_iteration_index, self._default.current_index) self.assertIs(self._default.previous_iteration, self._default.previous) self.assertIs(self._default.previous_iteration_index, self._default.previous_index) self.assertIs(self._default.first_iteration, self._default.first) self.assertIs(self._default.last_iteration, self._default.last) self.assertIs(self._default.last_iteration_index, self._default.last_index)