def test_can_decrease_weight_in_3heap_with_3_elements(self): dheap = DHeap(3) dheap.insert(5) dheap.insert(3) dheap.insert(1) dheap_min = dheap.min() dheap.decrease_weight(1, dheap.heap[1]-dheap_min+1) self.assertEqual(dheap.min(), 0)
def test_can_decrease_weight_in_4heap_with_10_elements_10_times(self): dheap = DHeap(4) for i in range(10, 0, -1): dheap.insert(i) for i in range(10): dheap.decrease_weight(9, 2) self.assertEqual(dheap.min(), min(dheap.heap))
def test_can_delete_min_of_4heap_with_10_elements_3_times(self): dheap = DHeap(4) for i in range(10, 0, -1): dheap.insert(i) for i in range(3): dheap_min = dheap.min() dheap.delete_min() self.assertTrue(dheap_min not in dheap.heap)
def test_can_delete_from_4heap_with_10_elements_10_times(self): dheap = DHeap(4) for i in range(10, 0, -1): dheap.insert(i) for i in range(9): dheap_elem_to_delete = dheap.heap[1] dheap.delete(1) self.assertTrue(dheap_elem_to_delete not in dheap.heap and dheap.min() == 1)
def test_can_delete_min_of_3heap_with_3_elements(self): dheap = DHeap(3) dheap.insert(5) dheap.insert(3) dheap.insert(1) dheap_min = dheap.min() dheap.delete_min() self.assertTrue(dheap_min not in dheap.heap)
def test_can_delete_from_3heap_with_3_elements(self): dheap = DHeap(3) dheap.insert(5) dheap.insert(3) dheap.insert(1) dheap_elem_to_delete = dheap.heap[1] dheap.delete(1) self.assertTrue(dheap_elem_to_delete not in dheap.heap and dheap.min() == 1)
def test_can_get_min_of_4heap_with_10_elements(self): dheap = DHeap(4) for i in range(10, 0, -1): dheap.insert(i) self.assertEqual(dheap.min(), 1)
def test_can_get_min_of_3heap_with_3_elements(self): dheap = DHeap(3) dheap.insert(5) dheap.insert(3) dheap.insert(1) self.assertEqual(dheap.min(), 1)
def test_can_create_4heap_with_10_elements_from_list(self): dheap = DHeap(4, list(range(10, 0, -1))) for i in range(10): self.assertEqual(dheap.min(), min(dheap.heap)) dheap.delete_min()
def test_can_create_3heap_with_3_elements_from_list(self): dheap = DHeap(3, [5, 1, 3]) for i in range(3): self.assertEqual(dheap.min(), min(dheap.heap)) dheap.delete_min()