diff options
author | Damien George <damien.p.george@gmail.com> | 2014-08-26 09:31:26 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-08-26 09:31:26 +0100 |
commit | 779794a68085eda5176694437523d43b953a8651 (patch) | |
tree | 59e40a02781a6137bdd388635d073e48f6cd2083 /tests/basics | |
parent | fa1a9bc9fd1683f1fb68739efc1aef303c8a1d2d (diff) | |
download | micropython-779794a68085eda5176694437523d43b953a8651.tar.gz micropython-779794a68085eda5176694437523d43b953a8651.zip |
py: Add dispatch for user defined ==, >, <=, >=.
Addresses issue #827.
Diffstat (limited to 'tests/basics')
-rw-r--r-- | tests/basics/class_binop.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/basics/class_binop.py b/tests/basics/class_binop.py new file mode 100644 index 0000000000..774f0afaf9 --- /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)) |