summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compare.py
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2001-01-03 02:13:26 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2001-01-03 02:13:26 (GMT)
commite7e694fd22fd68f39d359b3d1d5a1f0ebb4ec265 (patch)
tree6a99b5249ee3b6da0283fcadd8b615c5feca12c0 /Lib/test/test_compare.py
parent38796d07a535618a9c12217c3d6d5d0309fceed5 (diff)
downloadcpython-e7e694fd22fd68f39d359b3d1d5a1f0ebb4ec265.zip
cpython-e7e694fd22fd68f39d359b3d1d5a1f0ebb4ec265.tar.gz
cpython-e7e694fd22fd68f39d359b3d1d5a1f0ebb4ec265.tar.bz2
Use == rather than cmp(). The return value of cmp() is not well defined when
comparing different types.
Diffstat (limited to 'Lib/test/test_compare.py')
-rw-r--r--Lib/test/test_compare.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/Lib/test/test_compare.py b/Lib/test/test_compare.py
index d74f300..e8698a9 100644
--- a/Lib/test/test_compare.py
+++ b/Lib/test/test_compare.py
@@ -17,7 +17,7 @@ class Coerce:
if isinstance(other, Coerce):
return self.arg, other.arg
else:
- return (self.arg, other)
+ return self.arg, other
class Cmp:
def __init__(self,arg):
@@ -40,18 +40,20 @@ class RCmp:
return cmp(other, self.arg)
-candidates = [2, 2.2, 2L, 2+4j, [1], (2,), None, Empty(), Coerce(3),
- Cmp(4), RCmp(5)]
+candidates = [2, 2.0, 2L, 2+0j, [1], (3,), None, Empty(), Coerce(2),
+ Cmp(2.0), RCmp(2L)]
def test():
for a in candidates:
for b in candidates:
- print "cmp(%s, %s)" % (a, b),
try:
- x = cmp(a, b)
+ x = a == b
except:
- print '... %s' % sys.exc_info(0)
+ print 'cmp(%s, %s) => %s' % (a, b, sys.exc_info()[0])
else:
- print '=', x
+ if x:
+ print "%s == %s" % (a, b)
+ else:
+ print "%s != %s" % (a, b)
test()