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.

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