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.

33 lines
1.3 KiB

2 months ago
  1. import pycarl
  2. from configurations import PackageSelector, parser
  3. @parser
  4. class TestParse(PackageSelector):
  5. def test_parse_number(self, package):
  6. num = pycarl.parse.deserialize("2", package)
  7. assert num == package.Rational(2)
  8. num = pycarl.parse.deserialize("-2", package)
  9. assert num == package.Rational(-2)
  10. num = pycarl.parse.deserialize("(- 2)", package)
  11. assert num == package.Rational(-2)
  12. def test_parse_polynomial(self, package):
  13. pol = pycarl.parse.deserialize("(+ y 1)", package)
  14. assert str(pol) == "y+1"
  15. def test_parse_rational_function(self, package):
  16. rf = pycarl.parse.deserialize("(/ (+ x 1) (+ y 1))", package)
  17. x = pycarl.variable_with_name("x")
  18. y = pycarl.variable_with_name("y")
  19. assert package.numerator(rf) == package.Polynomial(x) + 1
  20. def test_parse_constraint(self, package):
  21. constraint = pycarl.parse.deserialize("(< x 0)", package)
  22. assert str(constraint) == "x<0"
  23. constraint = pycarl.parse.deserialize("(< x 1)", package)
  24. x = pycarl.variable_with_name("x")
  25. assert constraint.lhs == x - package.Rational(1)
  26. constraint = pycarl.parse.deserialize("(<= (* (- 1) x) 0)", package)
  27. assert constraint.lhs == -package.Polynomial(x)