def test_real(self): """Create Real using different constant types.""" from fractions import Fraction as pyFraction from pysmt.constants import HAS_GMPY v1 = (1,2) v2 = 0.5 v3 = pyFraction(1,2) v4 = Fraction(1,2) c1 = self.mgr.Real(v1) c2 = self.mgr.Real(v2) c3 = self.mgr.Real(v3) c4 = self.mgr.Real(v4) self.assertIs(c1, c2) self.assertIs(c2, c3) self.assertIs(c3, c4) if HAS_GMPY: from gmpy2 import mpq, mpz v5 = (mpz(1), mpz(2)) v6 = mpq(1,2) c5 = self.mgr.Real(v5) c6 = self.mgr.Real(v6) self.assertIs(c4, c5) self.assertIs(c5, c6)
def test_is_methods(self): from fractions import Fraction as pyFraction self.assertFalse(is_pysmt_fraction(4)) self.assertTrue(is_pysmt_fraction(Fraction(4))) self.assertFalse(is_pysmt_integer(4.0)) self.assertTrue(is_pysmt_integer(Integer(4))) self.assertTrue(is_python_integer(int(2))) if PY2: self.assertTrue(is_python_integer(long(2))) if HAS_GMPY: from gmpy2 import mpz self.assertTrue(is_python_integer(mpz(1))) if HAS_GMPY: from gmpy2 import mpz, mpq self.assertTrue(is_python_rational(mpz(1))) self.assertTrue(is_python_rational(mpq(1))) if PY2: self.assertTrue(is_python_rational(long(1))) self.assertTrue(is_python_rational(pyFraction(5))) self.assertTrue(is_python_rational(3)) self.assertTrue(is_python_boolean(True)) self.assertTrue(is_python_boolean(False))
def test_pysmt_integer_from_integer(self): from fractions import Fraction as pyFraction self.assertEqual(Integer(4), pysmt_integer_from_integer(4)) self.assertEqual(Integer(4), pysmt_integer_from_integer(Integer(4))) self.assertEqual(Integer(4), pysmt_integer_from_integer(Fraction(4))) self.assertEqual(Integer(4), pysmt_integer_from_integer(pyFraction(4)))
def test_is_methods(self): self.assertFalse(is_pysmt_fraction(4)) self.assertTrue(is_pysmt_fraction(Fraction(4))) self.assertFalse(is_pysmt_integer(4.0)) self.assertTrue(is_pysmt_integer(Integer(4))) self.assertTrue(is_python_integer(int(2))) if PY2: self.assertTrue(is_python_integer(long(2))) if HAS_GMPY: from gmpy2 import mpz self.assertTrue(is_python_integer(mpz(1))) if HAS_GMPY: from gmpy2 import mpz, mpq self.assertTrue(is_python_rational(mpz(1))) self.assertTrue(is_python_rational(mpq(1))) if PY2: self.assertTrue(is_python_rational(long(1))) self.assertTrue(is_python_rational(pyFraction(5))) self.assertTrue(is_python_rational(3)) self.assertTrue(is_python_boolean(True)) self.assertTrue(is_python_boolean(False))
def test_real(self): """Create Real using different constant types.""" from fractions import Fraction as pyFraction from pysmt.constants import HAS_GMPY v1 = (1, 2) v2 = 0.5 v3 = pyFraction(1, 2) v4 = Fraction(1, 2) c1 = self.mgr.Real(v1) c2 = self.mgr.Real(v2) c3 = self.mgr.Real(v3) c4 = self.mgr.Real(v4) self.assertIs(c1, c2) self.assertIs(c2, c3) self.assertIs(c3, c4) if HAS_GMPY: from gmpy2 import mpq, mpz v5 = (mpz(1), mpz(2)) v6 = mpq(1, 2) c5 = self.mgr.Real(v5) c6 = self.mgr.Real(v6) self.assertIs(c4, c5) self.assertIs(c5, c6)
def test_pysmt_fraction_from_rational(self): from fractions import Fraction as pyFraction self.assertEqual(Fraction(4,5), pysmt_fraction_from_rational("4/5")) self.assertEqual(Fraction(4,5), pysmt_fraction_from_rational(pyFraction(4,5))) self.assertEqual(Fraction(4,5), pysmt_fraction_from_rational(Fraction(4,5))) self.assertEqual(Fraction(4), pysmt_fraction_from_rational(4)) self.assertEqual(Fraction(4), pysmt_fraction_from_rational(Integer(4)))
def test_to_python_integer(self): from fractions import Fraction as pyFraction res = long(4) if PY2 else int(4) self.assertEqual(res, to_python_integer(pysmt_integer_from_integer(4))) self.assertEqual(res, to_python_integer(pysmt_integer_from_integer(Integer(4)))) self.assertEqual(res, to_python_integer(pysmt_integer_from_integer(Fraction(4)))) self.assertEqual(res, to_python_integer(pysmt_integer_from_integer(pyFraction(4))))
def test_pysmt_fraction_from_rational(self): self.assertEqual(Fraction(4, 5), pysmt_fraction_from_rational("4/5")) self.assertEqual(Fraction(4, 5), pysmt_fraction_from_rational(pyFraction(4, 5))) self.assertEqual(Fraction(4, 5), pysmt_fraction_from_rational(Fraction(4, 5))) self.assertEqual(Fraction(4), pysmt_fraction_from_rational(4)) self.assertEqual(Fraction(4), pysmt_fraction_from_rational(Integer(4)))
def test_to_python_integer(self): res = long(4) if PY2 else int(4) self.assertEqual(res, to_python_integer(pysmt_integer_from_integer(4))) self.assertEqual( res, to_python_integer(pysmt_integer_from_integer(Integer(4)))) self.assertEqual( res, to_python_integer(pysmt_integer_from_integer(Fraction(4)))) self.assertEqual( res, to_python_integer(pysmt_integer_from_integer(pyFraction(4))))
def test_pysmt_integer_from_integer(self): self.assertEqual(Integer(4), pysmt_integer_from_integer(4)) self.assertEqual(Integer(4), pysmt_integer_from_integer(Integer(4))) self.assertEqual(Integer(4), pysmt_integer_from_integer(Fraction(4))) self.assertEqual(Integer(4), pysmt_integer_from_integer(pyFraction(4)))