You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
5.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. import stormpy
  2. import stormpy.logic
  3. from helpers.helper import get_example_path
  4. import pytest
  5. class TestModel:
  6. def test_build_dtmc_from_prism_program(self):
  7. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  8. model = stormpy.build_model(program)
  9. assert model.nr_states == 13
  10. assert model.nr_transitions == 20
  11. assert model.model_type == stormpy.ModelType.DTMC
  12. assert not model.supports_parameters
  13. assert type(model) is stormpy.SparseDtmc
  14. def test_build_dtmc_from_prism_program_formulas(self):
  15. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  16. prop = "P=? [F \"one\"]"
  17. properties = stormpy.parse_properties_for_prism_program(prop, program, None)
  18. model = stormpy.build_model(program, properties)
  19. assert model.nr_states == 13
  20. assert model.nr_transitions == 20
  21. assert model.model_type == stormpy.ModelType.DTMC
  22. assert not model.supports_parameters
  23. assert type(model) is stormpy.SparseDtmc
  24. def test_build_parametric_dtmc_from_prism_program(self):
  25. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  26. prop = "P=? [F s=5]"
  27. formulas = stormpy.parse_properties_for_prism_program(prop, program)
  28. model = stormpy.build_parametric_model(program, formulas)
  29. assert model.nr_states == 613
  30. assert model.nr_transitions == 803
  31. assert model.model_type == stormpy.ModelType.DTMC
  32. assert model.supports_parameters
  33. assert model.has_parameters
  34. assert type(model) is stormpy.SparseParametricDtmc
  35. def test_build_dtmc_from_jani_model(self):
  36. jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani"))
  37. model = stormpy.build_model(jani_model)
  38. assert model.nr_states == 13
  39. assert model.nr_transitions == 20
  40. assert model.model_type == stormpy.ModelType.DTMC
  41. assert not model.supports_parameters
  42. assert type(model) is stormpy.SparseDtmc
  43. def test_build_dtmc(self):
  44. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  45. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  46. model = stormpy.build_model(program, formulas)
  47. assert model.nr_states == 13
  48. assert model.nr_transitions == 20
  49. assert model.model_type == stormpy.ModelType.DTMC
  50. assert not model.supports_parameters
  51. assert type(model) is stormpy.SparseDtmc
  52. def test_build_dtmc_with_undefined_constants(self):
  53. jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "brp.jani"))
  54. assert jani_model.has_undefined_constants
  55. assert not jani_model.undefined_constants_are_graph_preserving
  56. with pytest.raises(stormpy.StormError):
  57. model = stormpy.build_model(jani_model)
  58. def test_build_instantiated_dtmc(self):
  59. jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "brp.jani"))
  60. assert jani_model.has_undefined_constants
  61. assert not jani_model.undefined_constants_are_graph_preserving
  62. description = stormpy.SymbolicModelDescription(jani_model)
  63. constant_definitions = description.parse_constant_definitions("N=16, MAX=2")
  64. instantiated_jani_model = description.instantiate_constants(constant_definitions).as_jani_model()
  65. model = stormpy.build_model(instantiated_jani_model)
  66. assert model.nr_states == 677
  67. assert model.nr_transitions == 867
  68. assert model.model_type == stormpy.ModelType.DTMC
  69. assert not model.supports_parameters
  70. assert type(model) is stormpy.SparseDtmc
  71. def test_build_parametric_dtmc(self):
  72. program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
  73. formulas = stormpy.parse_properties_for_prism_program("P=? [ F s=5 ]", program)
  74. model = stormpy.build_parametric_model(program, formulas)
  75. assert model.nr_states == 613
  76. assert model.nr_transitions == 803
  77. assert model.model_type == stormpy.ModelType.DTMC
  78. assert model.supports_parameters
  79. assert model.has_parameters
  80. assert type(model) is stormpy.SparseParametricDtmc
  81. def test_build_dtmc_supporting_parameters(self):
  82. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  83. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  84. model = stormpy.build_parametric_model(program, formulas)
  85. assert model.nr_states == 13
  86. assert model.nr_transitions == 20
  87. assert model.model_type == stormpy.ModelType.DTMC
  88. assert model.supports_parameters
  89. assert not model.has_parameters
  90. assert type(model) is stormpy.SparseParametricDtmc
  91. def test_initial_states(self):
  92. program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
  93. formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
  94. model = stormpy.build_model(program, formulas)
  95. initial_states = model.initial_states
  96. assert len(initial_states) == 1
  97. assert 0 in initial_states