def test_engine_error(self): """ Test an engine can raises a non-StopIteration error. """ s = Simulator(max_iterations=5) s.network = Network("Iteration test network") s.add_engine(TypeErrorEngine(None, error_on_iteration=1)) s.add_engine(CountEngine(None)) s.timesteps = [0, ] with self.assertRaises(TypeError): s.start()
def test_engine_iteration(self): """ Test setting the global number of iterations in a simulator. """ s = Simulator(max_iterations=5) s.network = Network("Iteration test network") engine = CountEngine(None) s.add_engine(engine) s.timesteps = [0, ] s.start() assert engine.iteration == 5 assert engine.run_count == 5
def test_default_iteration(self): """ Test that the default simulation `max_iterations` is one. """ s = Simulator() s.network = Network("Iteration test network") engine = CountEngine(None) s.add_engine(engine) s.timesteps = [0, ] s.start() assert engine.iteration == 1 assert engine.run_count == 1
def test_engine_error(self): """ Test an engine can raises a non-StopIteration error. """ s = Simulator(max_iterations=5) s.network = Network("Iteration test network") s.add_engine(TypeErrorEngine(None, error_on_iteration=1)) s.add_engine(CountEngine(None)) s.timesteps = [ 0, ] with self.assertRaises(TypeError): s.start()
def test_engine_iteration(self): """ Test setting the global number of iterations in a simulator. """ s = Simulator(max_iterations=5) s.network = Network("Iteration test network") engine = CountEngine(None) s.add_engine(engine) s.timesteps = [ 0, ] s.start() assert engine.iteration == 5 assert engine.run_count == 5
def test_default_iteration(self): """ Test that the default simulation `max_iterations` is one. """ s = Simulator() s.network = Network("Iteration test network") engine = CountEngine(None) s.add_engine(engine) s.timesteps = [ 0, ] s.start() assert engine.iteration == 1 assert engine.run_count == 1
def test_dict_overwrite(self): """ Test to ensure that dictionaries and other objects contained in history are not overwritten by maintaining references to the same objects. """ print("Testing...") network = Network("History Test Network") network.add_node(HistoryTestNode(x=0, y=0, name="Test Node")) s = Simulator() s.network = network s.timesteps = ['a', 'b', 'c'] s.start() assert s.network.nodes[0]._history['property_dict'] == [{'test': 'a'}, {'test': 'b'}, {'test': 'c'}]
def test_engine_stopping_iteration(self): """ Test an engine terminating iteration The engine must raise a `StopIteration` exception. """ s = Simulator(max_iterations=5) s.network = Network("Iteration test network") stopper_engine = StopperEngine(None, stop_on_iteration=2) s.add_engine(stopper_engine) engine = CountEngine(None) s.add_engine(engine) s.timesteps = [0, ] s.start() assert engine.iteration == 1 assert engine.run_count == 1 assert stopper_engine.iteration == 2
def test_engine_stopping_iteration(self): """ Test an engine terminating iteration The engine must raise a `StopIteration` exception. """ s = Simulator(max_iterations=5) s.network = Network("Iteration test network") stopper_engine = StopperEngine(None, stop_on_iteration=2) s.add_engine(stopper_engine) engine = CountEngine(None) s.add_engine(engine) s.timesteps = [ 0, ] s.start() assert engine.iteration == 1 assert engine.run_count == 1 assert stopper_engine.iteration == 2
def test_dict_overwrite(self): """ Test to ensure that dictionaries and other objects contained in history are not overwritten by maintaining references to the same objects. """ print("Testing...") network = Network("History Test Network") network.add_node(HistoryTestNode(x=0, y=0, name="Test Node")) s = Simulator() s.network = network s.timesteps = ['a', 'b', 'c'] s.start() assert s.network.nodes[0]._history['property_dict'] == [{ 'test': 'a' }, { 'test': 'b' }, { 'test': 'c' }]