summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_deque.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-04-03 23:20:46 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-04-03 23:20:46 (GMT)
commit44459debc620106ed156c6ae8bc32ec02e3dec98 (patch)
tree168e377d9f3b1314365a55a3cae3a33048653021 /Lib/test/test_deque.py
parent4893abc77ab88fbcd3a80c5017194088cb3d5a61 (diff)
downloadcpython-44459debc620106ed156c6ae8bc32ec02e3dec98.zip
cpython-44459debc620106ed156c6ae8bc32ec02e3dec98.tar.gz
cpython-44459debc620106ed156c6ae8bc32ec02e3dec98.tar.bz2
Add count() method to collections.deque().
Diffstat (limited to 'Lib/test/test_deque.py')
-rw-r--r--Lib/test/test_deque.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index a2f5fae..17d724c 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -114,6 +114,30 @@ class TestBasic(unittest.TestCase):
d = deque('abc')
d.maxlen = 10
+ def test_count(self):
+ for s in ('', 'abracadabra', 'simsalabim'*500+'abc'):
+ s = list(s)
+ d = deque(s)
+ for letter in 'abcdefghijklmnopqrstuvwxyz':
+ self.assertEqual(s.count(letter), d.count(letter), (s, d, letter))
+ self.assertRaises(TypeError, d.count) # too few args
+ self.assertRaises(TypeError, d.count, 1, 2) # too many args
+ class BadCompare:
+ def __eq__(self, other):
+ raise ArithmeticError
+ d = deque([1, 2, BadCompare(), 3])
+ self.assertRaises(ArithmeticError, d.count, 2)
+ d = deque([1, 2, 3])
+ self.assertRaises(ArithmeticError, d.count, BadCompare())
+ class MutatingCompare:
+ def __eq__(self, other):
+ self.d.pop()
+ return True
+ m = MutatingCompare()
+ d = deque([1, 2, 3, m, 4, 5])
+ m.d = d
+ self.assertRaises(RuntimeError, d.count, 3)
+
def test_comparisons(self):
d = deque('xabc'); d.popleft()
for e in [d, deque('abc'), deque('ab'), deque(), list(d)]: