Ejemplo n.º 1
0
 def test_min_heap_property(self):
     min_heap = MinHeap(self.array)
     length = min_heap.length()
     elements = min_heap.elements()
     for i in range(0, length):
         current_value = elements[i]
         left_index = (2 * i) + 1
         right_index = (2 * i) + 2
         if left_index <= length - 1:
             self.assertLessEqual(current_value, elements[left_index])
         if right_index <= length - 1:
             self.assertLessEqual(current_value, elements[right_index])
Ejemplo n.º 2
0
 def test_delete_element_at_index_minheap(self):
     min_heap = MinHeap(self.array)
     min_heap.delete_element_at_index(3)
     self.assertEqual(4, min_heap.length())
     self.assertEqual([3, 4, 6, 11], min_heap.elements())
Ejemplo n.º 3
0
 def test_add_element_to_minheap(self):
     min_heap = MinHeap(self.array)
     min_heap.add_element(1)
     self.assertEqual(6, min_heap.length())
     self.assertEqual([1, 4, 3, 8, 11, 6], min_heap.elements())
     self.assertEqual(1, min_heap.get_root_value())
Ejemplo n.º 4
0
 def test_add_array_of_elements_to_minheap(self):
     min_heap = MinHeap(self.array)
     min_heap.add_element([1, 14, 7, 5])
     self.assertEqual(9, min_heap.length())
     self.assertEqual([1, 4, 3, 5, 11, 6, 14, 8, 7], min_heap.elements())
     self.assertEqual(1, min_heap.get_root_value())
Ejemplo n.º 5
0
 def test_min_heap_count_and_elements(self):
     min_heap = MinHeap(self.array)
     self.assertEqual(5, min_heap.length())
     self.assertEqual([3, 4, 6, 8, 11], min_heap.elements())