diff options
author | Raymond Hettinger <python@rcn.com> | 2010-04-03 10:32:58 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2010-04-03 10:32:58 (GMT) |
commit | 9c01e441bb2589853446787d4150fe623050a1e1 (patch) | |
tree | fe8479098709faeb7bfd9c7e4b47091c6e0e0212 /Lib/test | |
parent | 03d788dc4d6d399ba1092da5895edd7e6900345a (diff) | |
download | cpython-9c01e441bb2589853446787d4150fe623050a1e1.zip cpython-9c01e441bb2589853446787d4150fe623050a1e1.tar.gz cpython-9c01e441bb2589853446787d4150fe623050a1e1.tar.bz2 |
Add a subtract() method to collections.Counter()
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_collections.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 797b350..1bd49d9 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -661,6 +661,16 @@ class TestCounter(unittest.TestCase): set_result = setop(set(p.elements()), set(q.elements())) self.assertEqual(counter_result, dict.fromkeys(set_result, 1)) + def test_subtract(self): + c = Counter(a=-5, b=0, c=5, d=10, e=15,g=40) + c.subtract(a=1, b=2, c=-3, d=10, e=20, f=30, h=-50) + self.assertEqual(c, Counter(a=-6, b=-2, c=8, d=0, e=-5, f=-30, g=40, h=50)) + c = Counter(a=-5, b=0, c=5, d=10, e=15,g=40) + c.subtract(Counter(a=1, b=2, c=-3, d=10, e=20, f=30, h=-50)) + self.assertEqual(c, Counter(a=-6, b=-2, c=8, d=0, e=-5, f=-30, g=40, h=50)) + c = Counter('aaabbcd') + c.subtract('aaaabbcce') + self.assertEqual(c, Counter(a=-1, b=0, c=-1, d=1, e=-1)) class TestOrderedDict(unittest.TestCase): |