def test_nlargest(self): m = MinHeap(1024, [1, 2, 3, 4, 2, 1, 5, 6]) l = list(m.nlargest(3)) l.sort() self.assertEqual(l, [4, 5, 6])
def test_pop(self): m = MinHeap(1024, (3, 5, 2, 1)) self.assertEqual(m.pop(), 1) self.assertEqual(m.pop(), 2) self.assertEqual(m.pop(), 3) self.assertEqual(m.pop(), 5)
def test_push(self): m = MinHeap(1024, ()) m.push(1) m.push(3) m.push(2) self.assertEqual(m.pop(), 1) self.assertEqual(m.pop(), 2) self.assertEqual(m.pop(), 3) m.push(1) m.push(3) m.push(2) m.push(4) m.push(6) m.push(5) self.assertEqual(m.pop(), 1) self.assertEqual(m.pop(), 2) self.assertEqual(m.pop(), 3) self.assertEqual(m.pop(), 4) self.assertEqual(m.pop(), 5) self.assertEqual(m.pop(), 6)