def test_add(self): s = zset() s.add(3, 'ciao') s.add(4, 'bla') self.assertEqual(len(s), 2) s.add(-1, 'bla') self.assertEqual(len(s), 2) data = list(s) self.assertEqual(data, ['bla', 'ciao'])
def test_update(self): string = test.populate('string', size=100) values = test.populate('float', size=100) s = zset() s.update(zip(values, string)) self.assertTrue(s) prev = None for score, _ in s.items(): if prev is not None: self.assertTrue(score >= prev) prev = score return s
def test_update(self): string = test.populate('string', size=100) values = test.populate('float', size=100) s = zset() s.update(zip(values,string)) self.assertTrue(s) prev = None for score, _ in s.items(): if prev is not None: self.assertTrue(score>=prev) prev = score return s
def test_rank(self): s = zset() s.add(3, 'ciao') s.add(4, 'bla') s.add(2, 'foo') s.add(20, 'pippo') s.add(-1, 'bla') self.assertEqual(len(s), 4) self.assertEqual(s.rank('bla'), 0) self.assertEqual(s.rank('foo'), 1) self.assertEqual(s.rank('ciao'), 2) self.assertEqual(s.rank('pippo'), 3) self.assertEqual(s.rank('xxxx'), None)
def set_cache(self, data): if self.cache is None: self.cache = zset() self.cache.update(data)
def clear(self): self.cache = None self.toadd = zset() self.toremove = set()