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_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 _apply_infix(self, right, function, bv_function=None): if _env().enable_infix_notation: mgr = _mgr() # BVs # Default bv_function to function if bv_function is None: bv_function = function if _is_bv(self): if is_python_integer(right): right = mgr.BV(right, width=self.bv_width()) return bv_function(self, right) # Boolean, Integer and Arithmetic if is_python_boolean(right): right = mgr.Bool(right) elif is_python_integer(right): ty = self.get_type() if ty.is_real_type(): right = mgr.Real(right) else: right = mgr.Int(right) elif is_python_rational(right): right = mgr.Real(right) return function(self, right) else: raise Exception("Cannot use infix notation")
def _apply_infix(self, right, function, bv_function=None): if _env().enable_infix_notation: mgr = _mgr() # BVs # Default bv_function to function if bv_function is None: bv_function = function if _is_bv(self): if is_python_integer(right): right = mgr.BV(right, width=self.bv_width()) return bv_function(self, right) # Boolean, Integer and Arithmetic if is_python_boolean(right): right = mgr.Bool(right) elif is_python_integer(right): ty = self.get_type() if ty.is_real_type(): right = mgr.Real(right) else: right = mgr.Int(right) elif is_python_rational(right): right = mgr.Real(right) return function(self, right) else: raise PysmtModeError("Cannot use infix notation")