Пример #1
0
 def test_add_element_to_maxheap(self):
     max_heap = MaxHeap(self.array)
     max_heap.add_element(13)
     self.assertEqual(6, max_heap.length())
     self.assertEqual([13, 8, 11, 4, 3, 6], max_heap.elements())
     self.assertEqual(13, max_heap.get_root_value())
     self.assertEqual([13, 8, 11, 4, 3, 6], max_heap.elements())
Пример #2
0
 def test_max_heap_property(self):
     max_heap = MaxHeap(self.array)
     length = max_heap.length()
     elements = max_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.assertGreaterEqual(current_value, elements[left_index])
         if right_index <= length - 1:
             self.assertGreaterEqual(current_value, elements[right_index])
Пример #3
0
 def test_max_heap_count_and_elements(self):
     max_heap = MaxHeap(self.array)
     self.assertEqual(5, max_heap.length())
     self.assertEqual([11, 8, 6, 4, 3], max_heap.elements())
Пример #4
0
 def test_delete_element_at_index_maxheap(self):
     max_heap = MaxHeap(self.array)
     max_heap.delete_element_at_index(2)
     self.assertEqual(4, max_heap.length())
     self.assertEqual([11, 8, 3, 4], max_heap.elements())
Пример #5
0
 def test_add_array_of_elements_to_maxheap(self):
     max_heap = MaxHeap(self.array)
     max_heap.add_element([1, 14, 7, 5])
     self.assertEqual(9, max_heap.length())
     self.assertEqual([14, 8, 11, 7, 3, 1, 6, 4, 5], max_heap.elements())
     self.assertEqual(14, max_heap.get_root_value())