예제 #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_multiple_operations_maxheap(self):
     max_heap = MaxHeap(self.array)
     max_heap.add_element(5)
     self.assertEqual([11, 8, 6, 4, 3, 5], max_heap.elements())
     self.assertEqual(11, max_heap.extract_root())
     self.assertEqual([8, 5, 6, 4, 3], max_heap.elements())
     max_heap.add_element([11, 13, 5, 6])
     self.assertEqual([13, 6, 11, 5, 3, 6, 8, 4, 5], max_heap.elements())
     self.assertEqual(13, max_heap.extract_root())
     self.assertEqual(11, max_heap.extract_root())
     self.assertEqual([8, 6, 6, 5, 3, 4, 5], max_heap.elements())
     self.assertEqual([3, 4, 5, 5, 6, 6, 8], sorted(max_heap.elements()))
예제 #3
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())