From 60f29149efe0b57b24a47889200f5e3a2be0a78f Mon Sep 17 00:00:00 2001 From: Adam Kelly Date: Sun, 4 Nov 2018 10:17:07 +0000 Subject: [PATCH] Add test for class with sub and rsub. --- tests/snippets/subtraction.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/snippets/subtraction.py diff --git a/tests/snippets/subtraction.py b/tests/snippets/subtraction.py new file mode 100644 index 000000000..3471c1545 --- /dev/null +++ b/tests/snippets/subtraction.py @@ -0,0 +1,21 @@ +assert 5 - 3 == 2 + +class Complex(): + def __init__(self, real, imag): + self.real = real + self.imag = imag + + def __repr__(self): + return "Com" + str((self.real, self.imag)) + + def __sub__(self, other): + return Complex(self.real - other, self.imag) + + def __rsub__(self, other): + return Complex(other - self.real, -self.imag) + + def __eq__(self, other): + return self.real == other.real and self.imag == other.imag + +assert Complex(4, 5) - 3 == Complex(1, 5) +assert 7 - Complex(4, 5) == Complex(3, -5)