Issue #11004: Repair edge case in deque.count().

(Reviewed by Georg Brandl.)

Also made similar changes to deque.reverse() though this wasn't
strictly necessary (the edge case cannot occur with two pointers
moving to meet in the middle).  Making the change in reverse()
was more a matter of future-proofing.
This commit is contained in:
Raymond Hettinger 2011-01-25 21:32:39 +00:00
parent 5543e81352
commit 512d2cc643
3 changed files with 18 additions and 4 deletions

View file

@ -138,6 +138,15 @@ class TestBasic(unittest.TestCase):
m.d = d
self.assertRaises(RuntimeError, d.count, 3)
# test issue11004
# block advance failed after rotation aligned elements on right side of block
d = deque([None]*16)
for i in range(len(d)):
d.rotate(-1)
d.rotate(1)
self.assertEqual(d.count(1), 0)
self.assertEqual(d.count(None), 16)
def test_comparisons(self):
d = deque('xabc'); d.popleft()
for e in [d, deque('abc'), deque('ab'), deque(), list(d)]: