From ae61e178eca0220093c00b548d5d80afba4e5c54 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 9 Oct 2003 03:59:36 +0000 Subject: [PATCH] Added reset() to smallqueue. --- src/structures.py | 6 ++++++ test/test_structures.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/structures.py b/src/structures.py index 6469b514f..ae2aa4213 100644 --- a/src/structures.py +++ b/src/structures.py @@ -294,6 +294,12 @@ class smallqueue(list): def peek(self): return self[0] + def __repr__(self): + return 'smallqueue([%s])' % ', '.join(map(repr, self)) + + def reset(self): + self[:] = [] + class MaxLengthQueue(queue): __slots__ = ('length',) diff --git a/test/test_structures.py b/test/test_structures.py index a381dcb1d..fa3a94201 100644 --- a/test/test_structures.py +++ b/test/test_structures.py @@ -199,6 +199,13 @@ class RingBufferTestCase(unittest.TestCase): class QueueTest(unittest.TestCase): + def testReset(self): + q = queue() + q.enqueue(1) + self.assertEqual(len(q), 1) + q.reset() + self.assertEqual(len(q), 0) + def testGetitem(self): q = queue() n = 10 @@ -357,6 +364,13 @@ class QueueTest(unittest.TestCase): queue = smallqueue class SmallQueueTest(unittest.TestCase): + def testReset(self): + q = queue() + q.enqueue(1) + self.assertEqual(len(q), 1) + q.reset() + self.assertEqual(len(q), 0) + def testGetitem(self): q = queue() n = 10