def test_popitem_ties(self): from discodop.util import PyAgenda h = PyAgenda() for i in range(TestHeap.testN): h[i] = 0. for i in range(TestHeap.testN): _, v = h.popitem() self.assertEqual(v, 0.)
def test_init_small(self): from discodop.util import PyAgenda for data in ([(0, 3), (1, 7), (2, 1)], [(0, 7), (1, 3), (2, 1)], [(0, 7), (1, 3), (2, 7)]): h = PyAgenda(data) self.assertEqual( [h.popitem(), h.popitem(), h.popitem()], sorted(data, key=itemgetter(1))) self.assertEqual(len(h), 0)
def test_init(self): from discodop.util import PyAgenda h, pairs, d = self.make_data() h = PyAgenda(d.items()) while pairs: v = h.popitem() v2 = pairs.pop() self.assertEqual(v, v2) d.pop(v[0]) self.assertEqual(len(h), len(d)) self.assertEqual(len(h), 0)
def make_data(self): from random import random from discodop.util import PyAgenda pairs = [(random(), random()) for _ in range(TestHeap.testN)] h = PyAgenda() d = {} for k, v in pairs: h[k] = v d[k] = v pairs.sort(key=itemgetter(1), reverse=True) return h, pairs, d