summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_richcmp.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-01-18 16:21:57 (GMT)
committerGuido van Rossum <guido@python.org>2001-01-18 16:21:57 (GMT)
commit890f20961912efbdb3d9223f27507e9de0a697e7 (patch)
treecab7ff6b58fb3c754ab01038417bb5a82528a1ff /Lib/test/test_richcmp.py
parent1c2fb9ce29a9b0bddecd6fb275121c9fdc4ea3e6 (diff)
downloadcpython-890f20961912efbdb3d9223f27507e9de0a697e7.zip
cpython-890f20961912efbdb3d9223f27507e9de0a697e7.tar.gz
cpython-890f20961912efbdb3d9223f27507e9de0a697e7.tar.bz2
Add test for comparing recursive data types.
Diffstat (limited to 'Lib/test/test_richcmp.py')
-rw-r--r--Lib/test/test_richcmp.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py
index 83cb72b..796e698 100644
--- a/Lib/test/test_richcmp.py
+++ b/Lib/test/test_richcmp.py
@@ -1,6 +1,6 @@
# Tests for rich comparisons
-from test_support import TestFailed, verify
+from test_support import TestFailed, verify, verbose
class Number:
@@ -188,6 +188,46 @@ def misbehavin():
else:
raise TestFailed, "cmp(Misb(), Misb()) didn't raise RuntimeError"
+def recursion():
+ from UserList import UserList
+ a = UserList(); a.append(a)
+ b = UserList(); b.append(b)
+ def check(s, a=a, b=b):
+ if verbose:
+ print "trying", s, "..."
+ verify(eval(s))
+ if verbose:
+ print "recursion tests: a=%s, b=%s" % (a, b)
+ check('a==b')
+ check('a<=b')
+ check('a>=b')
+ check('not a<b')
+ check('not a>b')
+ check('not a!=b')
+ check('cmp(a,b) == 0')
+ a.append(1)
+ b.append(0)
+ if verbose:
+ print "recursion tests: a=%s, b=%s" % (a, b)
+ check('a>b')
+ check('a>=b')
+ check('a!=b')
+ check('not a<b')
+ check('not a<=b')
+ check('not a==b')
+ check('cmp(a,b) == 1')
+ a[1] = -1
+ if verbose:
+ print "recursion tests: a=%s, b=%s" % (a, b)
+ check('a<b')
+ check('a<=b')
+ check('a!=b')
+ check('not a>b')
+ check('not a>=b')
+ check('not a==b')
+ check('cmp(a,b) == -1')
+ if verbose: print "recursion tests ok"
+
def main():
basic()
tabulate()
@@ -195,5 +235,6 @@ def main():
tabulate(c2=int)
testvector()
misbehavin()
+ recursion()
main()