def test_binary_heap_sort(self): print("Inserting Elements in Binary Heap") bh = MinBinaryHeap() elements: List[int] = [random.randrange(0, 1000) for _ in range(10)] #elements:List[int] = [76, 984, 610, 238, 347, 633, 915, 576, 403, 165] print('Elements are:{}'.format(elements)) for key in elements: bh.insert_element_min_heap(key) sorted_list: List[int] = bh.heap_sort() print("Elements after heap sort are : {}".format(sorted_list)) elements.sort() self.assertEqual(elements, sorted_list)
def test_binary_heap_insertion(self): print("Inserting Elements in Binary Heap") bh = MinBinaryHeap() elements: List[int] = [random.randrange(0, 1000) for _ in range(10)] #elements:List[int] = [761, 327, 332, 385, 605, 772, 945, 737, 976, 518] print('Elements are:{}'.format(elements)) for key in elements: bh.insert_element_min_heap(key) print("Heap after Elements insertion are") bh.print()
def test_duplicate(): h = MinBinaryHeap([1, 2, 3]) h.push(1) assert h.heap_list == [1, 1, 3, 2]
def test_edge_case(): h = MinBinaryHeap([1, 5, 8, 7, 9, 10, 11]) h.push(4) assert h.heap_list == [1, 4, 8, 5, 9, 10, 11, 7]