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.

55 lines
2.2 KiB

2 months ago
  1. import stormpy
  2. import stormpy.utility
  3. import pytest
  4. class TestSmtSolver():
  5. def test_smtsolver_init(self):
  6. manager = stormpy.ExpressionManager()
  7. solver = stormpy.utility.Z3SmtSolver(manager)
  8. def test_smtsolver_trivial(self):
  9. manager = stormpy.ExpressionManager()
  10. solver = stormpy.utility.Z3SmtSolver(manager)
  11. solver.add(manager.create_boolean(True))
  12. assert solver.check() != stormpy.utility.SmtCheckResult.Unsat
  13. assert solver.check() == stormpy.utility.SmtCheckResult.Sat
  14. solver.add(manager.create_boolean(False))
  15. assert solver.check() == stormpy.utility.SmtCheckResult.Unsat
  16. assert solver.check() != stormpy.utility.SmtCheckResult.Sat
  17. def test_smtsolver_arithmetic_unsat(self):
  18. manager = stormpy.ExpressionManager()
  19. x = manager.create_integer_variable("x")
  20. xe = x.get_expression()
  21. c1 = stormpy.Expression.Geq(xe, manager.create_integer(1))
  22. c2 = stormpy.Expression.Less(xe, manager.create_integer(0))
  23. solver = stormpy.utility.Z3SmtSolver(manager)
  24. solver.add(c1)
  25. solver.add(c2)
  26. assert solver.check() == stormpy.utility.SmtCheckResult.Unsat
  27. def test_smtsolver_arithmetic_unsat(self):
  28. manager = stormpy.ExpressionManager()
  29. x = manager.create_integer_variable("x")
  30. xe = x.get_expression()
  31. c1 = stormpy.Expression.Geq(xe, manager.create_integer(1))
  32. c2 = stormpy.Expression.Less(xe, manager.create_integer(0))
  33. solver = stormpy.utility.Z3SmtSolver(manager)
  34. solver.add(c1)
  35. solver.add(c2)
  36. assert solver.check() == stormpy.utility.SmtCheckResult.Unsat
  37. def test_smtsolver_arithmetic_unsat(self):
  38. manager = stormpy.ExpressionManager()
  39. x = manager.create_integer_variable("x")
  40. xe = x.get_expression()
  41. c1 = stormpy.Expression.Geq(xe, manager.create_integer(1))
  42. c2 = stormpy.Expression.Less(xe, manager.create_integer(2))
  43. solver = stormpy.utility.Z3SmtSolver(manager)
  44. solver.add(c1)
  45. solver.add(c2)
  46. assert solver.check() == stormpy.utility.SmtCheckResult.Sat
  47. assert solver.model.get_integer_value(x) == 1