示例#1
0
 def update(self):
     c = Counter()
     c.update('aababc')
     Assert(c) == Counter('aababc')
     c.update({'b': 1})
     Assert(c['b']) == 3
     c.update(c=2)
     Assert(c['c']) == 3
示例#2
0
 def most_common(self):
     c = Counter('aababc')
     result = [('a', 3), ('b', 2), ('c', 1)]
     Assert(c.most_common()) == result
     Assert(c.most_common(2)) == result[:-1]
     Assert(c.most_common(1)) == result[:-2]
     Assert(c.most_common(0)) == []
示例#3
0
 def __init__(self, mapping=(), maxsize=float('inf')):
     dict.__init__(self, mapping)
     self.maxsize = maxsize
     self.usage_counter = Counter()
示例#4
0
 def or_and(self):
     c1 = Counter('abc')
     new = c1 | c1 * 2
     Assert(new.values()) == [2] * 3
     new = c1 & c1 * 2
     Assert(new.values()) == [1] * 3
示例#5
0
 def sub(self):
     c = Counter('aababc')
     assert not c - c
示例#6
0
 def mul(self):
     c = Counter('abc')
     Assert(c * 2) == c + c
示例#7
0
 def add(self):
     c = Counter('aababc')
     new = c + c
     Assert(new['a']) == 6
     Assert(new['b']) == 4
     Assert(new['c']) == 2
示例#8
0
 def elements(self):
     c = Counter('aababc')
     for element in c:
         Assert(list(c.elements()).count(element)) == c[element]
示例#9
0
 def setdefault(self):
     c = Counter('a')
     Assert(c.setdefault('a', 2)) == 1
     Assert(c['a']) == 1
     Assert(c.setdefault('b')) == 1
     Assert(c['b']) == 1
示例#10
0
 def get(self):
     c = Counter('a')
     Assert(c.get('a')) == 1
     Assert(c.get('b')) == 0
示例#11
0
 def missing(self):
     c = Counter()
     Assert(c['a']) == 0