def test_analyze_mttf(self): dft = stormpy.dft.load_dft_json_file( get_example_path("dft", "and.json")) formulas = stormpy.parse_properties("T=? [ F \"failed\" ]") assert dft.nr_elements() == 3 results = stormpy.dft.analyze_dft(dft, [formulas[0].raw_formula]) assert math.isclose(results[0], 3)
def test_load_dft_json_file(self): dft = stormpy.dft.load_dft_json_file( get_example_path("dft", "and.json")) assert dft.nr_elements() == 3 assert dft.nr_be() == 2 assert dft.nr_dynamic() == 0 assert not dft.can_have_nondeterminism()
def test_load_dft_galileo_file(self): dft = stormpy.dft.load_dft_galileo_file( get_example_path("dft", "hecs.dft")) assert dft.nr_elements() == 23 assert dft.nr_be() == 13 assert dft.nr_dynamic() == 2 assert not dft.can_have_nondeterminism()
def test_modularisation(self): dft = stormpy.dft.load_dft_galileo_file( get_example_path("dft", "hecs.dft")) assert dft.nr_elements() == 23 assert dft.nr_be() == 13 assert dft.nr_dynamic() == 2 dfts = dft.modularisation() assert len(dfts) == 4 for ft in dfts: assert ft.top_level_element.name in ["n116", "n137", "n120", "n21"]
def test_export_dft_json_string(self): dft = stormpy.dft.load_dft_galileo_file( get_example_path("dft", "hecs.dft")) assert dft.nr_elements() == 23 assert dft.nr_be() == 13 assert dft.nr_dynamic() == 2 json_string = stormpy.dft.export_dft_json_string(dft) dft2 = stormpy.dft.load_dft_json_string(json_string) assert dft2.nr_elements() == 23 assert dft2.nr_be() == 13 assert dft2.nr_dynamic() == 2
def test_export_dft_json_file(self, tmpdir): dft = stormpy.dft.load_dft_galileo_file( get_example_path("dft", "hecs.dft")) assert dft.nr_elements() == 23 assert dft.nr_be() == 13 assert dft.nr_dynamic() == 2 export_file = os.path.join(str(tmpdir), "hecs.json") stormpy.dft.export_dft_json_file(dft, export_file) dft2 = stormpy.dft.load_dft_json_file(export_file) assert dft2.nr_elements() == 23 assert dft2.nr_be() == 13 assert dft2.nr_dynamic() == 2
def test_load_dft_json_string(self): # Build json string json_node_a = '{"data": {"id":"0", "name":"A", "type":"be", "rate":"1", "dorm":"1", "label":"A (1)"}, "group":"nodes", "classes":"be"}' json_node_b = '{"data": {"id":"1", "name":"B", "type":"be", "rate":"1", "dorm":"1", "label":"B (1)"}, "group":"nodes", "classes":"be"}' json_node_c = '{"data": {"id":"6", "name":"Z", "type":"pand", "children":["0", "1"], "label":"Z"}, "group":"nodes", "classes":"pand"}' json_string = '{"toplevel": "6", "parameters": {}, "nodes": [' + json_node_a + ',' + json_node_b + ',' + json_node_c + ']}' # Load dft = stormpy.dft.load_dft_json_string(json_string) assert dft.nr_elements() == 3 assert dft.nr_be() == 2 assert dft.nr_dynamic() == 1 assert not dft.can_have_nondeterminism()
def test_parametric_dft(self): import pycarl pycarl.clear_pools() dft = stormpy.dft.load_parametric_dft_galileo_file( get_example_path("dft", "symmetry_param.dft")) assert dft.nr_elements() == 7 assert dft.nr_be() == 4 assert dft.nr_dynamic() == 0 assert type(dft) is stormpy.dft.DFT_ratfunc parameters = stormpy.dft.get_parameters(dft) param_names = [x.name for x in parameters] assert "x" in param_names assert "y" in param_names
def test_instantiate_dft(self): pycarl.clear_pools() dft = stormpy.dft.load_parametric_dft_galileo_file( get_example_path("dft", "symmetry_param.dft")) assert dft.nr_elements() == 7 assert dft.nr_be() == 4 instantiator = stormpy.dft.DFTInstantiator(dft) x = pycarl.variable_with_name("x") y = pycarl.variable_with_name("y") valuation = {x: stormpy.RationalRF("5"), y: stormpy.RationalRF("0.01")} inst_dft = instantiator.instantiate(valuation) assert inst_dft.nr_elements() == 7 assert inst_dft.nr_be() == 4 elem = inst_dft.get_element_by_name("C") assert str(elem) == "{C} BE exp(5, 0.05)" elem = inst_dft.get_element_by_name("D") assert str(elem) == "{D} BE exp(0.01, 0)"
def test_element(self): dft = stormpy.dft.load_dft_json_file( get_example_path("dft", "and.json")) tle = dft.top_level_element assert dft.nr_elements() == 3 assert dft.nr_be() == 2 assert dft.nr_dynamic() == 0 assert tle.id == 2 assert tle.name == "A" b = dft.get_element(0) assert b.id == 0 assert b.name == "B" c = dft.get_element_by_name("C") assert c.id == 1 assert c.name == "C" # Invalid name should raise exception with pytest.raises(RuntimeError) as exception: d = dft.get_element_by_name("D") assert "InvalidArgumentException" in str(exception.value)