summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-05-12 20:55:56 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-05-12 20:55:56 (GMT)
commit0e371f2cb6178de7344c97e4a546703c4bba140e (patch)
tree52fd07c90da0c60ee0c65fa991f7d27db49f00c3 /Lib
parentfd3f4fb7b114e177767568da35eee2241a8eda18 (diff)
downloadcpython-0e371f2cb6178de7344c97e4a546703c4bba140e.zip
cpython-0e371f2cb6178de7344c97e4a546703c4bba140e.tar.gz
cpython-0e371f2cb6178de7344c97e4a546703c4bba140e.tar.bz2
Make sure "del d[n]" is properly supported. Was necessary because the
same method that implements __setitem__ also implements __delitem__. Also, there were several good use cases (removing items from a queue and implementing Forth style stack ops).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_deque.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index e8d9ce4..9b857c5 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -90,6 +90,20 @@ class TestBasic(unittest.TestCase):
l[i] = 7*i
self.assertEqual(list(d), l)
+ def test_delitem(self):
+ n = 500 # O(n**2) test, don't make this too big
+ d = deque(xrange(n))
+ self.assertRaises(IndexError, d.__delitem__, -n-1)
+ self.assertRaises(IndexError, d.__delitem__, n)
+ for i in xrange(n):
+ self.assertEqual(len(d), n-i)
+ j = random.randrange(-len(d), len(d))
+ val = d[j]
+ self.assert_(val in d)
+ del d[j]
+ self.assert_(val not in d)
+ self.assertEqual(len(d), 0)
+
def test_rotate(self):
s = tuple('abcde')
n = len(s)
@@ -476,9 +490,7 @@ deque(['c', 'b', 'a'])
-
>>> def delete_nth(d, n):
-... "del d[n]"
... d.rotate(-n)
... d.popleft()
... d.rotate(n)
@@ -524,7 +536,6 @@ h
>>> print maketree('abcdefgh')
[[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]]
-
"""