From 491b8f0501c7b3d8b7c33d85a430845d245da5c9 Mon Sep 17 00:00:00 2001 From: Vivien Maisonneuve Date: Wed, 11 Jun 2014 20:19:20 +0200 Subject: [PATCH 1/1] Fix Expression.__rsub__ --- pypol/linear.py | 3 ++- tests/test_linear.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pypol/linear.py b/pypol/linear.py index de6f4ca..c169049 100644 --- a/pypol/linear.py +++ b/pypol/linear.py @@ -158,7 +158,8 @@ class Expression: constant = self.constant - other.constant return Expression(coefficients, constant) - __rsub__ = __sub__ + def __rsub__(self, other): + return -(self - other) @_polymorphic_method def __mul__(self, other): diff --git a/tests/test_linear.py b/tests/test_linear.py index 93fc838..4079d75 100644 --- a/tests/test_linear.py +++ b/tests/test_linear.py @@ -99,6 +99,7 @@ class TestExpression(unittest.TestCase): def test_sub(self): self.assertEqual(self.x - self.x, 0) self.assertEqual(self.e - 3, self.x - 2*self.y) + self.assertEqual(0 - self.x, -self.x) def test_mul(self): self.assertEqual(self.pi * 7, 22) -- 2.20.1