From 0e371f2cb6178de7344c97e4a546703c4bba140e Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 12 May 2004 20:55:56 +0000 Subject: 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). --- Lib/test/test_deque.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Lib/test/test_deque.py') diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index e8d9ce49c7..9b857c5d47 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']]]] - """ -- cgit v1.2.1