mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Add support for unary plus and unary minus to collections.Counter()
This commit is contained in:
parent
18205baf25
commit
fcb393c018
4 changed files with 31 additions and 1 deletions
|
@ -943,6 +943,11 @@ class TestCounter(unittest.TestCase):
|
|||
c.subtract('aaaabbcce')
|
||||
self.assertEqual(c, Counter(a=-1, b=0, c=-1, d=1, e=-1))
|
||||
|
||||
def test_unary(self):
|
||||
c = Counter(a=-5, b=0, c=5, d=10, e=15,g=40)
|
||||
self.assertEqual(dict(+c), dict(c=5, d=10, e=15, g=40))
|
||||
self.assertEqual(dict(-c), dict(a=5))
|
||||
|
||||
def test_helper_function(self):
|
||||
# two paths, one for real dicts and one for other mappings
|
||||
elems = list('abracadabra')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue