From 779794a68085eda5176694437523d43b953a8651 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 26 Aug 2014 09:31:26 +0100 Subject: py: Add dispatch for user defined ==, >, <=, >=. Addresses issue #827. --- tests/basics/class_binop.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/basics/class_binop.py (limited to 'tests/basics') diff --git a/tests/basics/class_binop.py b/tests/basics/class_binop.py new file mode 100644 index 000000000..774f0afaf --- /dev/null +++ b/tests/basics/class_binop.py @@ -0,0 +1,31 @@ +class foo(object): + def __init__(self, value): + self.x = value + + def __eq__(self, other): + print('eq') + return self.x == other.x + + def __lt__(self, other): + print('lt') + return self.x < other.x + + def __gt__(self, other): + print('gt') + return self.x > other.x + + def __le__(self, other): + print('le') + return self.x <= other.x + + def __ge__(self, other): + print('ge') + return self.x >= other.x + +for i in range(3): + for j in range(3): + print(foo(i) == foo(j)) + print(foo(i) < foo(j)) + print(foo(i) > foo(j)) + print(foo(i) <= foo(j)) + print(foo(i) >= foo(j)) -- cgit v1.2.3