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): 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_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_integer(self): """Create Int using different constant types.""" from pysmt.constants import HAS_GMPY v_base = Integer(1) c_base = self.mgr.Int(v_base) v_int = int(1) c_int = self.mgr.Int(v_int) self.assertIs(c_base, c_int) if HAS_GMPY: from gmpy2 import mpz v_mpz = mpz(1) c_mpz = self.mgr.Int(v_mpz) self.assertIs(c_base, c_mpz)
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)))