summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/special_comparisons.py33
-rw-r--r--tests/basics/special_comparisons2.py31
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/basics/special_comparisons.py b/tests/basics/special_comparisons.py
new file mode 100644
index 000000000..2ebd7e224
--- /dev/null
+++ b/tests/basics/special_comparisons.py
@@ -0,0 +1,33 @@
+class A:
+ def __eq__(self, other):
+ print("A __eq__ called")
+ return True
+
+class B:
+ def __ne__(self, other):
+ print("B __ne__ called")
+ return True
+
+class C:
+ def __eq__(self, other):
+ print("C __eq__ called")
+ return False
+
+class D:
+ def __ne__(self, other):
+ print("D __ne__ called")
+ return False
+
+a = A()
+b = B()
+c = C()
+d = D()
+
+def test(s):
+ print(s)
+ print(eval(s))
+
+for x in 'abcd':
+ for y in 'abcd':
+ test('{} == {}'.format(x,y))
+ test('{} != {}'.format(x,y))
diff --git a/tests/basics/special_comparisons2.py b/tests/basics/special_comparisons2.py
new file mode 100644
index 000000000..c29dc72ce
--- /dev/null
+++ b/tests/basics/special_comparisons2.py
@@ -0,0 +1,31 @@
+class E:
+ def __repr__(self):
+ return "E"
+
+ def __eq__(self, other):
+ print('E eq', other)
+ return 123
+
+class F:
+ def __repr__(self):
+ return "F"
+
+ def __ne__(self, other):
+ print('F ne', other)
+ return -456
+
+print(E() != F())
+print(F() != E())
+
+tests = (None, 0, 1, 'a')
+
+for val in tests:
+ print('==== testing', val)
+ print(E() == val)
+ print(val == E())
+ print(E() != val)
+ print(val != E())
+ print(F() == val)
+ print(val == F())
+ print(F() != val)
+ print(val != F())