MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / test_heap

Function test_heap

data_structures/heap/heap_generic.py:131–168  ·  view source on GitHub ↗

>>> h = Heap() # Max-heap >>> h.insert_item(5, 34) >>> h.insert_item(6, 31) >>> h.insert_item(7, 37) >>> h.get_top() [7, 37] >>> h.extract_top() [7, 37] >>> h.extract_top() [5, 34] >>> h.extract_top() [6, 31] >>> h = Heap(key=lambda x: -x) # Min

()

Source from the content-addressed store, hash-verified

129
130
131def test_heap() -> None:
132 """
133 >>> h = Heap() # Max-heap
134 >>> h.insert_item(5, 34)
135 >>> h.insert_item(6, 31)
136 >>> h.insert_item(7, 37)
137 >>> h.get_top()
138 [7, 37]
139 >>> h.extract_top()
140 [7, 37]
141 >>> h.extract_top()
142 [5, 34]
143 >>> h.extract_top()
144 [6, 31]
145 >>> h = Heap(key=lambda x: -x) # Min heap
146 >>> h.insert_item(5, 34)
147 >>> h.insert_item(6, 31)
148 >>> h.insert_item(7, 37)
149 >>> h.get_top()
150 [6, -31]
151 >>> h.extract_top()
152 [6, -31]
153 >>> h.extract_top()
154 [5, -34]
155 >>> h.extract_top()
156 [7, -37]
157 >>> h.insert_item(8, 45)
158 >>> h.insert_item(9, 40)
159 >>> h.insert_item(10, 50)
160 >>> h.get_top()
161 [9, -40]
162 >>> h.update_item(10, 30)
163 >>> h.get_top()
164 [10, -30]
165 >>> h.delete_item(10)
166 >>> h.get_top()
167 [9, -40]
168 """
169
170
171if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected