summaryrefslogtreecommitdiff
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2008-11-12 23:23:36 +0000
committerMark Dickinson <dickinsm@gmail.com>2008-11-12 23:23:36 +0000
commit4a1f593df5d4733831a1c4f03ca40c701433c43d (patch)
tree0aea7b57d9c6fad40a32cca6be0993bd607ed9e2 /Lib/test/test_float.py
parent3d4ca74bc85c4224498e75704f82e4d42b6a04df (diff)
downloadcpython-git-4a1f593df5d4733831a1c4f03ca40c701433c43d.tar.gz
Issue #4296: Fix PyObject_RichCompareBool so that "x in [x]" evaluates to
True, even when x doesn't compare equal to itself. This was a regression from 2.6. Reviewed by R. Hettinger and C. Heimes.
Diffstat (limited to 'Lib/test/test_float.py')
-rw-r--r--Lib/test/test_float.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index 4f8446a98d..2d3b3575cc 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -117,6 +117,33 @@ class GeneralFloatCases(unittest.TestCase):
self.assertRaises(OverflowError, float('-inf').as_integer_ratio)
self.assertRaises(ValueError, float('nan').as_integer_ratio)
+ def test_float_containment(self):
+ floats = (INF, -INF, 0.0, 1.0, NAN)
+ for f in floats:
+ self.assert_(f in [f], "'%r' not in []" % f)
+ self.assert_(f in (f,), "'%r' not in ()" % f)
+ self.assert_(f in {f}, "'%r' not in set()" % f)
+ self.assert_(f in {f: None}, "'%r' not in {}" % f)
+ self.assertEqual([f].count(f), 1, "[].count('%r') != 1" % f)
+ self.assert_(f in floats, "'%r' not in container" % f)
+
+ for f in floats:
+ # nonidentical containers, same type, same contents
+ self.assert_([f] == [f], "[%r] != [%r]" % (f, f))
+ self.assert_((f,) == (f,), "(%r,) != (%r,)" % (f, f))
+ self.assert_({f} == {f}, "{%r} != {%r}" % (f, f))
+ self.assert_({f : None} == {f: None}, "{%r : None} != "
+ "{%r : None}" % (f, f))
+
+ # identical containers
+ l, t, s, d = [f], (f,), {f}, {f: None}
+ self.assert_(l == l, "[%r] not equal to itself" % f)
+ self.assert_(t == t, "(%r,) not equal to itself" % f)
+ self.assert_(s == s, "{%r} not equal to itself" % f)
+ self.assert_(d == d, "{%r : None} not equal to itself" % f)
+
+
+
class FormatFunctionsTestCase(unittest.TestCase):
def setUp(self):