1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/operator_support.py Sat Dec 10 14:02:44 2016 +0100
1.3 @@ -0,0 +1,28 @@
1.4 +class A:
1.5 + def __init__(self, x):
1.6 + self.x = x
1.7 + def __sub__(self, other):
1.8 + return self.x - other.x
1.9 +
1.10 +class B:
1.11 + def __init__(self, x):
1.12 + self.x = x
1.13 + def __rsub__(self, other):
1.14 + return other.x - self.x
1.15 +
1.16 +class C:
1.17 + def __init__(self, x):
1.18 + self.x = x
1.19 +
1.20 +a = A(10)
1.21 +b = B(5)
1.22 +c = C(3)
1.23 +
1.24 +print a - b # 5
1.25 +print c - b # -2
1.26 +print a - c # 7
1.27 +
1.28 +try:
1.29 + print b - c # should raise an exception
1.30 +except TypeError:
1.31 + print "b - c: b and c do not respectively support the __sub__ and __rsub__ operations"