コード例 #1
0
ファイル: test_formula.py プロジェクト: pysmt/pysmt
    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)
コード例 #2
0
    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))
コード例 #3
0
    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)))
コード例 #4
0
ファイル: test_constants.py プロジェクト: mpreiner/pysmt
    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))
コード例 #5
0
ファイル: test_formula.py プロジェクト: mitar/pysmt
    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)
コード例 #6
0
ファイル: test_constants.py プロジェクト: agriggio/pysmt
    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)))
コード例 #7
0
ファイル: test_constants.py プロジェクト: agriggio/pysmt
    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)))
コード例 #8
0
ファイル: test_constants.py プロジェクト: agriggio/pysmt
    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))))
コード例 #9
0
 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)))
コード例 #10
0
 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))))
コード例 #11
0
 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)))
コード例 #12
0
ファイル: test_constants.py プロジェクト: mpreiner/pysmt
 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)))