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.5 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. import pycarl
  2. import stormpy
  3. import stormpy.logic
  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_bounds(self):
  30. prop = "P=? [F \"one\"]"
  31. formula = stormpy.parse_properties(prop)[0].raw_formula
  32. assert not formula.has_bound
  33. prop = "P<0.4 [F \"one\"]"
  34. formula = stormpy.parse_properties(prop)[0].raw_formula
  35. assert formula.has_bound
  36. assert formula.threshold == pycarl.Rational("0.4")
  37. assert formula.comparison_type == stormpy.logic.ComparisonType.LESS
  38. # setter not currently implemented (non-trivial due to Expression container)
  39. #def test_set_bounds(self):
  40. # prop = "P<0.4 [F \"one\"]"
  41. # formula = stormpy.parse_properties(prop)[0].raw_formula
  42. # formula.threshold = pycarl.Rational("0.2")
  43. # formula.comparison_type = stormpy.logic.ComparisonType.GEQ
  44. # assert formula.threshold == pycarl.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