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.

70 lines
2.9 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. class TestFormulas:
  5. def test_probability_formula(self):
  6. formula_str = "P=? [F \"one\"]"
  7. properties = stormpy.parse_properties(formula_str)
  8. formula = properties[0].raw_formula
  9. assert type(formula) == stormpy.logic.ProbabilityOperator
  10. assert len(properties) == 1
  11. assert str(formula) == formula_str
  12. def test_reward_formula(self):
  13. formula_str = "R=? [F \"one\"]"
  14. properties = stormpy.parse_properties(formula_str)
  15. formula = properties[0].raw_formula
  16. assert type(formula) == stormpy.logic.RewardOperator
  17. assert len(properties) == 1
  18. assert str(formula) == "R[exp]=? [F \"one\"]"
  19. def test_formula_list(self):
  20. formulas = []
  21. prop = "=? [F \"one\"]"
  22. forms = stormpy.parse_properties("P" + prop)
  23. formulas.append(forms[0].raw_formula)
  24. forms = stormpy.parse_properties("R" + prop)
  25. formulas.append(forms[0].raw_formula)
  26. assert len(formulas) == 2
  27. assert str(formulas[0]) == "P" + prop
  28. assert str(formulas[1]) == "R[exp]" + prop
  29. def test_jani_formula(self):
  30. _, properties = stormpy.parse_jani_model(get_example_path("dtmc", "brp.jani"))
  31. for name, prop in properties.items():
  32. assert "Property_brp_" in name
  33. assert isinstance(prop, stormpy.Property)
  34. def test_bounds(self):
  35. prop = "P=? [F \"one\"]"
  36. formula = stormpy.parse_properties(prop)[0].raw_formula
  37. assert not formula.has_bound
  38. prop = "P<0.4 [F \"one\"]"
  39. formula = stormpy.parse_properties(prop)[0].raw_formula
  40. assert formula.has_bound
  41. assert formula.threshold == stormpy.Rational("0.4")
  42. assert formula.comparison_type == stormpy.logic.ComparisonType.LESS
  43. def test_set_bounds(self):
  44. prop = "P<0.4 [F \"one\"]"
  45. formula = stormpy.parse_properties(prop)[0].raw_formula
  46. expression_manager = stormpy.ExpressionManager()
  47. rational = stormpy.Rational("0.2")
  48. expression = expression_manager.create_rational(rational)
  49. formula.set_bound(stormpy.logic.ComparisonType.GEQ, expression)
  50. assert formula.threshold == stormpy.Rational("0.2")
  51. assert formula.comparison_type == stormpy.logic.ComparisonType.GEQ
  52. assert str(formula) == "P>=1/5 [F \"one\"]"
  53. def test_subformula(self):
  54. prop = "P=? [F \"one\"]"
  55. formula = stormpy.parse_properties(prop)[0].raw_formula
  56. assert type(formula) == stormpy.logic.ProbabilityOperator
  57. pathform = formula.subformula
  58. assert type(pathform) == stormpy.logic.EventuallyFormula
  59. labelform = pathform.subformula
  60. assert type(labelform) == stormpy.logic.AtomicLabelFormula
  61. prop = stormpy.core.Property("label-formula", labelform)
  62. assert prop.raw_formula == labelform