Exemple #1
0
    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_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)))
Exemple #3
0
    def Real(self, value):
        """ Returns a Real-type constant of the given value.

        value can be:
          - A Fraction(n,d)
          - A tuple (n,d)
          - A long or int n
          - A float
          - (Optionally) a mpq or mpz object
        """
        if value in self.real_constants:
            return self.real_constants[value]

        if is_pysmt_fraction(value):
            val = value
        elif type(value) == tuple:
            val = Fraction(value[0], value[1])
        elif is_python_rational(value):
            val = pysmt_fraction_from_rational(value)
        else:
            raise PysmtTypeError("Invalid type in constant. The type was:" + \
                                 str(type(value)))

        n = self.create_node(node_type=op.REAL_CONSTANT,
                             args=tuple(),
                             payload=val)
        self.real_constants[value] = n
        return n
Exemple #4
0
    def Real(self, value):
        """ Returns a Real-type constant of the given value.

        value can be:
          - A Fraction(n,d)
          - A tuple (n,d)
          - A long or int n
          - A float
          - (Optionally) a mpq or mpz object
        """
        if value in self.real_constants:
            return self.real_constants[value]

        if is_pysmt_fraction(value):
            val = value
        elif type(value) == tuple:
            val = Fraction(value[0], value[1])
        elif is_python_rational(value):
            val = pysmt_fraction_from_rational(value)
        else:
            raise PysmtTypeError("Invalid type in constant. The type was:" + \
                                 str(type(value)))

        n = self.create_node(node_type=op.REAL_CONSTANT,
                             args=tuple(),
                             payload=val)
        self.real_constants[value] = n
        return n