diff options
author | Raymond Hettinger <python@rcn.com> | 2010-04-03 23:20:46 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-04-03 23:20:46 (GMT) |
commit | 44459debc620106ed156c6ae8bc32ec02e3dec98 (patch) | |
tree | 168e377d9f3b1314365a55a3cae3a33048653021 /Lib | |
parent | 4893abc77ab88fbcd3a80c5017194088cb3d5a61 (diff) | |
download | cpython-44459debc620106ed156c6ae8bc32ec02e3dec98.zip cpython-44459debc620106ed156c6ae8bc32ec02e3dec98.tar.gz cpython-44459debc620106ed156c6ae8bc32ec02e3dec98.tar.bz2 |
Add count() method to collections.deque().
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_deque.py | 24 |
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)]: |