Пример #1
0
 def test_build_max_heap(self):        
     heap = MaxHeap()
     heap.heap = [16,4,10,14,7,9,3,2,8,1]
     heap._build_max_heap()
     self.assertEqual(heap.heap, [16,14,10,8,7,9,3,2,4,1])
     
     heap.set_heap([4,1,3,2,16,9,10,14,8,7])
     heap._build_max_heap()
     self.assertEqual(heap.heap, [16,14,10,8,7,9,3,2,4,1]) 
Пример #2
0
    def test_build_max_heap(self):
        heap = MaxHeap()
        heap.heap = [16, 4, 10, 14, 7, 9, 3, 2, 8, 1]
        heap._build_max_heap()
        self.assertEqual(heap.heap, [16, 14, 10, 8, 7, 9, 3, 2, 4, 1])

        heap.set_heap([4, 1, 3, 2, 16, 9, 10, 14, 8, 7])
        heap._build_max_heap()
        self.assertEqual(heap.heap, [16, 14, 10, 8, 7, 9, 3, 2, 4, 1])
Пример #3
0
 def test_max_heapify(self):
     heap = MaxHeap()
     heap.heap = [16,4,10,14,7,9,3,2,8,1]
     heap.heap_size = len(heap.heap)
     heap._max_heapify(1)
     self.assertEqual(heap.heap, [16,14,10,8,7,9,3,2,4,1]) 
Пример #4
0
 def test_max_heapify(self):
     heap = MaxHeap()
     heap.heap = [16, 4, 10, 14, 7, 9, 3, 2, 8, 1]
     heap.heap_size = len(heap.heap)
     heap._max_heapify(1)
     self.assertEqual(heap.heap, [16, 14, 10, 8, 7, 9, 3, 2, 4, 1])