return bool(self.constant)
def __repr__(self):
- return '{}({!r})'.format(self.__class__.__name__, self._constant)
-
+ if self.constant.denominator == 1:
+ return '{}({!r})'.format(self.__class__.__name__, self.constant)
+ else:
+ return '{}({!r}, {!r})'.format(self.__class__.__name__,
+ self.constant.numerator, self.constant.denominator)
class Symbol(Expression):
def test_repr(self):
self.assertEqual(repr(self.x), "Symbol('x')")
self.assertEqual(repr(self.one), 'Constant(1)')
+ self.assertEqual(repr(self.pi), 'Constant(22, 7)')
self.assertEqual(repr(self.expr), "Expression({'x': 1, 'y': -2}, 3)")
def test_fromstring(self):