def test_get_effective_paths_probability(self): """Should get the valid paths for each output probability""" m1 = ModelMock(self.dynamic_system) m2 = ModelMock(self.dynamic_system) m3 = ModelMock(self.dynamic_system) m11 = Path(m1, m1, ExpressionProperty(Value(0.1))) m12 = Path(m1, m2, ExpressionProperty(Value(0.3))) m13 = Path(m1, m3, ExpressionProperty(Value(0.6))) m23 = Path(m2, m3, ExpressionProperty(Value(1))) self.dynamic_system.link(m11) self.dynamic_system.link(m12) self.dynamic_system.link(m13) self.dynamic_system.link(m23) m1.get_output = lambda: 5 m2.get_output = lambda: 15 m3.get_output = lambda: 25 self.dynamic_system.schedule(m1, Decimal(10)) self.dynamic_system.schedule(m2, Decimal(10)) self.dynamic_system.schedule(m3, Decimal(10)) self.dynamic_system.get_output() self.assertEqual(1, len(self.dynamic_system._get_effective_paths(m1))) self.assertEqual({m23}, self.dynamic_system._get_effective_paths(m2))
def test_remove_path(self) -> None: """Removes a model of the dynamic system.""" m1 = BaseModelMock(self.dynamic_system) m2 = BaseModelMock(self.dynamic_system) m3 = BaseModelMock(self.dynamic_system) m12 = Path(m1, m2, ExpressionProperty(Value(1))) m23 = Path(m2, m3, ExpressionProperty(Value(1))) self.dynamic_system.link(m12) self.dynamic_system.link(m23) self.assertEqual({m12}, self.dynamic_system._paths[m1]) self.dynamic_system.unlink(m12) self.assertTrue(m1 not in self.dynamic_system._paths)
def setUp(self) -> None: """Set ups tests""" self.dynamic_system = DynamicSystemMock() self.model_1 = BaseModelMock(self.dynamic_system, "model 1") self.model_2 = BaseModelMock(self.dynamic_system, "model 2") self.path = Path(self.model_1, self.model_2, ExpressionProperty(Value(1)))
def test_save_and_load(self): m1 = ModelMock(self.experiment.dynamic_system) m2 = ModelMock(self.experiment.dynamic_system) m1.set_up_state(5) m2.set_up_state(10) self.experiment.dynamic_system.schedule(m1, Decimal(10)) m12 = Path(m1, m2, ExpressionProperty(Value(1))) self.experiment.dynamic_system.link(m12) data = self.experiment.save() loaded_experiment = self.experiment.load(data) models_expected = set( [m.get_id() for m in self.experiment.dynamic_system._models] ) models_actual = {m.get_id() for m in loaded_experiment.dynamic_system._models} paths_expected = {m.get_id() for m in self.experiment.dynamic_system._paths} paths_actual = {m.get_id() for m in loaded_experiment.dynamic_system._paths} self.assertEqual(models_expected, models_actual) self.assertEqual(paths_expected, paths_actual)
def test_get_affected_models_and_its_inputs(self): """Should get the affected models and its inputs""" m1 = ModelMock(self.dynamic_system) m2 = ModelMock(self.dynamic_system) m3 = ModelMock(self.dynamic_system) m12 = Path(m1, m2, ExpressionProperty(Value(1))) m13 = Path(m1, m3, ExpressionProperty(Value(1))) m23 = Path(m2, m3, ExpressionProperty(Value(1))) np.random.seed(42) self.dynamic_system.link(m12) self.dynamic_system.link(m13) self.dynamic_system.link(m23) m1.get_output = lambda: 5 m2.get_output = lambda: 15 m3.get_output = lambda: 25 self.dynamic_system.schedule(m1, Decimal(10)) self.dynamic_system.schedule(m2, Decimal(10)) self.dynamic_system.schedule(m3, Decimal(10)) self.dynamic_system.get_output() ( affected_models, inputs, ) = self.dynamic_system._get_affected_models_and_its_inputs() self.assertEqual({m2, m3}, affected_models) self.assertDictEqual( { m2: { m1.get_id(): 5 }, m3: { m1.get_id(): 5, m2.get_id(): 15 } }, inputs)
def test_set_weight(self): """Should set the weight of the path""" self.path.set_weight(ExpressionProperty(Value(5))) self.assertEqual(self.path.get_weight(), 5)