From: Vivien Maisonneuve Date: Fri, 23 May 2014 07:57:03 +0000 (+0200) Subject: String formatting for empty expressions X-Git-Tag: 1.0~267 X-Git-Url: https://scm.cri.ensmp.fr/git/linpy.git/commitdiff_plain/844f76f670a227d335e9bc539e1a61be7161452a?ds=inline;hp=841943174bb4d3b602e8e055592d8b54d1bb086d String formatting for empty expressions --- diff --git a/pypol/linear.py b/pypol/linear.py index 5b5d8aa..6550e92 100644 --- a/pypol/linear.py +++ b/pypol/linear.py @@ -206,6 +206,8 @@ class Expression: elif constant < 0: constant *= -1 string += ' - {}'.format(constant) + if string == '': + string = '0' return string def _parenstr(self, always=False): diff --git a/tests/test_linear.py b/tests/test_linear.py index 3912fd3..4636275 100644 --- a/tests/test_linear.py +++ b/tests/test_linear.py @@ -110,6 +110,7 @@ class TestExpression(unittest.TestCase): self.assertEqual(self.e / 2, self.x / 2 - self.y + Fraction(3, 2)) def test_str(self): + self.assertEqual(str(Expression()), '0') self.assertEqual(str(self.x), 'x') self.assertEqual(str(-self.x), '-x') self.assertEqual(str(self.pi), '22/7')