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.

37 lines
1.5 KiB

2 months ago
  1. import pycarl
  2. from pycarl.formula import Relation, FormulaType
  3. from configurations import PackageSelector
  4. class TestFormula(PackageSelector):
  5. def test_init_constraint(self, package):
  6. pycarl.clear_pools()
  7. x = pycarl.Variable("x")
  8. constraint = package.formula.Constraint(x, Relation.GREATER, package.Rational(3))
  9. formula = package.formula.Formula(constraint)
  10. def test_negation(self, package):
  11. pycarl.clear_pools()
  12. x = pycarl.Variable("x")
  13. constraint = package.formula.Constraint(x, Relation.GREATER, package.Rational(3))
  14. formula = package.formula.Formula(constraint)
  15. neg_formula = ~constraint
  16. assert neg_formula.type == FormulaType.CONSTRAINT
  17. assert str(~neg_formula) == str(formula)
  18. def test_conjunction(self, package):
  19. pycarl.clear_pools()
  20. x = pycarl.Variable("x")
  21. y = pycarl.Variable("y")
  22. constraint1 = package.formula.Constraint(x, Relation.GREATER, package.Rational(3))
  23. formula1 = package.formula.Formula(constraint1)
  24. constraint2 = package.formula.Constraint(y, Relation.EQ, package.Rational(2))
  25. formula2 = package.formula.Formula(constraint2)
  26. and_formula = formula1 & formula2
  27. assert and_formula.type == FormulaType.AND
  28. assert len(and_formula) == 2
  29. subformulas = and_formula.get_subformulas()
  30. assert len(subformulas) == 2
  31. assert str(subformulas[0]) == str(formula1)
  32. assert str(subformulas[1]) == str(formula2)