From 9e103619134c8839d143951c5b814bab500fcdcf Mon Sep 17 00:00:00 2001 From: Vivien Maisonneuve Date: Fri, 20 Jun 2014 09:54:32 +0200 Subject: [PATCH 1/1] Improve representation of Constants --- pypol/linear.py | 7 +++++-- tests/test_linear.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pypol/linear.py b/pypol/linear.py index 8fdece9..e6d442e 100644 --- a/pypol/linear.py +++ b/pypol/linear.py @@ -355,8 +355,11 @@ class Constant(Expression): 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): diff --git a/tests/test_linear.py b/tests/test_linear.py index b722726..2375092 100644 --- a/tests/test_linear.py +++ b/tests/test_linear.py @@ -131,6 +131,7 @@ class TestExpression(unittest.TestCase): 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): -- 2.20.1