def testSetZero(self):  # {{{
     """Setting to zero deletes"""
     a = multiset((10, 20, 30))
     a[10] = 0
     expected = set({20: 1, 30: 1}.items())
     self.assertEqual(set(a.items()), expected)
 def testBadNegative(self):  # {{{
     """Cannot set negative values"""
     a = multiset([20])
     msg = re.compile("Negative element counts are invalid: -100")
     self.assertRaisesEx(ValueError, a.__setitem__, 20, -100, exc_pattern=msg)
Ejemplo n.º 3
0
 def testBadDict(self): #{{{
     '''Dict with non-integer values will set keys with count 1'''
     test = {'hello': 'world', 'william': 400}
     expected = {'hello': 1, 'william': 400}
     a = multiset(test)
     self.assertEqual(dict(a), expected)
Ejemplo n.º 4
0
 def testIntersection(self): #{{{
     '''Intersection returns min count of common elements'''
     a = multiset({'hello': 100, 'world': 200})
     b = multiset({'hello': 2000, 'world': 10})
     self.assertEqual(dict(a & b), {'hello': 100, 'world': 10})
Ejemplo n.º 5
0
 def testMultiset(self): #{{{
     '''Pass another multiset will copy it unconditionally'''
     a = multiset(range(10))
     b = multiset(a)
     expected = [(i, 1) for i in a]
     self.assertEqual(b.items(), expected)
Ejemplo n.º 6
0
 def testGoodDict(self): #{{{
     '''Pass a dict with integer values'''
     test = {'hello': 20, 'world': 30}
     a = multiset(test)
     self.assertEqual(dict(a), test)
Ejemplo n.º 7
0
 def testNothing(self): #{{{
     '''Pass nothing or empty sequence'''
     a = multiset()
     self.assertFalse(a)
     a = multiset([])
     self.assertFalse(a)
Ejemplo n.º 8
0
 def testIter(self): #{{{
     '''Pass a hashable iter, sets count to one'''
     a = range(10)
     a = multiset(a)
     expected = [(i, 1) for i in a]
     self.assertEqual(a.items(), expected)
Ejemplo n.º 9
0
 def testHaveAll(self): #{{{
     '''Union contains all objects'''
     a = multiset(range(5))
     b = multiset((i, i) for i in xrange(5))
     self.assertEqual(dict(a|b), dict((i, 1 if i == 0 else i) for i in xrange(5)))
 def testSetDefault(self): #{{{
     '''Set default properly'''
     a = multiset()
     res = a.setdefault('h', 200)
     self.assertEqual(dict(a), {'h': 200})
     self.assertEqual(res, 200)
 def testDefault(self): #{{{
     '''Default set to 1'''
     a = multiset()
     res = a.setdefault('hello')
     self.assertEqual(dict(a), {'hello': 1})
     self.assertEqual(res, 1)