summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_deque.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-03-20 23:38:56 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-03-20 23:38:56 (GMT)
commit39dadf7abf24302185f69493808dfb61fb8c4073 (patch)
tree758036c47e6d407d9c4bb973bde7344f45c2ce65 /Lib/test/test_deque.py
parent17d3a58e39c003ba4eecc5b4854a42b5d2546242 (diff)
downloadcpython-39dadf7abf24302185f69493808dfb61fb8c4073.zip
cpython-39dadf7abf24302185f69493808dfb61fb8c4073.tar.gz
cpython-39dadf7abf24302185f69493808dfb61fb8c4073.tar.bz2
Issue 23705: Improve the performance of __contains__ checks for deques.
Diffstat (limited to 'Lib/test/test_deque.py')
-rw-r--r--Lib/test/test_deque.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 0eebbff..7d69448 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -164,6 +164,26 @@ class TestBasic(unittest.TestCase):
self.assertEqual(x > y, list(x) > list(y), (x,y))
self.assertEqual(x >= y, list(x) >= list(y), (x,y))
+ def test_contains(self):
+ n = 200
+
+ d = deque(range(n))
+ for i in range(n):
+ self.assertTrue(i in d)
+ self.assertTrue((n+1) not in d)
+
+ # Test detection of mutation during iteration
+ d = deque(range(n))
+ d[n//2] = MutateCmp(d, False)
+ with self.assertRaises(RuntimeError):
+ n in d
+
+ # Test detection of comparison exceptions
+ d = deque(range(n))
+ d[n//2] = BadCmp()
+ with self.assertRaises(RuntimeError):
+ n in d
+
def test_extend(self):
d = deque('a')
self.assertRaises(TypeError, d.extend, 1)