From 844f76f670a227d335e9bc539e1a61be7161452a Mon Sep 17 00:00:00 2001 From: Vivien Maisonneuve Date: Fri, 23 May 2014 09:57:03 +0200 Subject: [PATCH 1/1] String formatting for empty expressions --- pypol/linear.py | 2 ++ tests/test_linear.py | 1 + 2 files changed, 3 insertions(+) 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') -- 2.20.1