Skip to content

Commit 60f2914

Browse files
committed
Add test for class with sub and rsub.
1 parent 0f0de02 commit 60f2914

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/snippets/subtraction.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
assert 5 - 3 == 2
2+
3+
class Complex():
4+
def __init__(self, real, imag):
5+
self.real = real
6+
self.imag = imag
7+
8+
def __repr__(self):
9+
return "Com" + str((self.real, self.imag))
10+
11+
def __sub__(self, other):
12+
return Complex(self.real - other, self.imag)
13+
14+
def __rsub__(self, other):
15+
return Complex(other - self.real, -self.imag)
16+
17+
def __eq__(self, other):
18+
return self.real == other.real and self.imag == other.imag
19+
20+
assert Complex(4, 5) - 3 == Complex(1, 5)
21+
assert 7 - Complex(4, 5) == Complex(3, -5)

0 commit comments

Comments
 (0)