def test_heap_extracts(self): heap = Heap() heap.items = [-1, 0, 3, 5, 1] self.assertEqual(heap.extract_min(), -1) self.assertEqual(heap.items, [0, 1, 3, 5]) self.assertEqual(heap.extract_min(), 0) self.assertEqual(heap.items, [1, 5, 3]) self.assertEqual(heap.extract_min(), 1) self.assertEqual(heap.items, [3, 5]) self.assertEqual(heap.extract_min(), 3) self.assertEqual(heap.items, [5]) self.assertEqual(heap.extract_min(), 5) self.assertEqual(heap.items, [])
def test_heap_creation(self): heap = Heap() self.assertEqual(heap.items, []) heap.insert(3) self.assertEqual(heap.items, [3]) heap.insert(5) self.assertEqual(heap.items, [3, 5]) heap.insert(1) self.assertEqual(heap.items, [1, 5, 3]) heap.insert(-1) self.assertEqual(heap.items, [-1, 1, 3, 5]) heap.insert(0) self.assertEqual(heap.items, [-1, 0, 3, 5, 1])