Пример #1
0
 def test_merge(self):
     h1 = heap.BinaryHeap(self.items)
     h2 = heap.BinaryHeap((k + self.n, id_ + self.n) for k, id_ in self.items)
     h1.merge(h2)
     self.check_heap_property(h1)
Пример #2
0
 def test_decrease_key(self):
     h = heap.BinaryHeap(self.items)
     for k, id_ in self.items:
         h.decrease_key(id_, k - 100)
         self.check_heap_property(h)
Пример #3
0
 def test_insert(self):
     h = heap.BinaryHeap()
     for k, id_ in self.items:
         h.insert(k, id_)
         self.check_heap_property(h)
Пример #4
0
 def test_extract(self):
     h = heap.BinaryHeap(self.items)
     keys = []
     while h:
         keys.append(h.extract()[0])
     self.assertEqual(sorted(keys), keys)
Пример #5
0
 def test_construct(self):
     h = heap.BinaryHeap(self.items)
     self.check_heap_property(h)