>>> 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
()
| 129 | |
| 130 | |
| 131 | def 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 | |
| 171 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected