def test_5_extract_min(self): self.assertEqual(self.heap.extract_min().data, 0) resultant_heap = bh.ExplicitBinaryMinHeap( levelorder=[0, 1, 1, 3, 2, 2, 5, 9, 6, 7, 3, 8, 4]) self.assertEqual(self.heap, resultant_heap)
def test_6_replace_min(self): self.assertEqual(self.heap.replace_min(8).data, 0) resultant_heap = bh.ExplicitBinaryMinHeap( levelorder=[0, 1, 1, 3, 2, 2, 5, 9, 6, 7, 3, 8, 4, 8]) self.assertEqual(self.heap, resultant_heap)
def test_4_remove_min(self): self.heap.remove_min() resultant_heap = bh.ExplicitBinaryMinHeap( levelorder=[0, 1, 1, 3, 2, 2, 5, 9, 6, 7, 3, 8, 4]) self.assertEqual(self.heap, resultant_heap)
def test_2_remove(self): self.heap.remove(self.heap.root.right.left) resultant_heap = bh.ExplicitBinaryMinHeap( levelorder=[0, 1, 0, 3, 2, 4, 1, 9, 6, 7, 3, 8, 5]) self.assertEqual(self.heap, resultant_heap)
def test_1_insert(self): self.heap.insert(2) resultant_heap = bh.ExplicitBinaryMinHeap( levelorder=[0, 1, 0, 3, 2, 2, 1, 9, 6, 7, 3, 8, 4, 5, 2]) self.assertEqual(self.heap, resultant_heap)
def test_0__heapify(self): resultant_heap = bh.ExplicitBinaryMinHeap( levelorder=[0, 1, 0, 3, 2, 2, 1, 9, 6, 7, 3, 8, 4, 5]) # post-heapify state self.assertEqual(self.heap, resultant_heap)
def setUp(self): self.heap = bh.ExplicitBinaryMinHeap( levelorder=[9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 3, 2, 1, 0]) # pre-heapify state