def test_bubble_up(self): test_heap = ex9_code.Heap([]) test_heap._heap = [3, 2, 5] test_heap._bubble_up(1) self.assertEqual(test_heap._heap, [3, 2, 5], "Heap was not properly" " bubbled up.") test_heap._bubble_up(2) self.assertEqual(test_heap._heap, [5, 2, 3], "Heap was not properly" " bubbled up.")
def test_bubble_down(self): test_heap = ex9_code.Heap([]) test_heap._heap = [1, 2, 3] test_heap._bubble_down(1) self.assertEqual(test_heap._heap, [1, 2, 3], "Heap was not properly" " bubbled down.") test_heap._bubble_down(0) self.assertEqual(test_heap._heap, [2, 1, 3], "Heap was not properly" " bubbled down.")
def test_remove_from_multi_element_heap(self): test_heap = ex9_code.Heap([1, 2, 3]) ret = test_heap.remove_top() self.assertEqual(ret, 3, "Heap did not return top value") self.assertEqual(test_heap._heap, [2, 1], "Heap container was not " "properly modified following extraction") ret_1 = test_heap.remove_top() self.assertEqual(ret_1, 2, "Heap did not return top value") self.assertEqual(test_heap._heap, [1], "Heap container was not " "properly modified following extraction")
def test_insert_into_nonempty_heap(self): test_heap = ex9_code.Heap([0]) test_heap.insert(1) self.assertEqual(test_heap._heap, [1, 0], "Heap does not contain" "assigned value") test_heap.insert(2) self.assertEqual(test_heap._heap, [2, 0, 1], "Heap does not contain" "assigned value") test_heap.insert(1) self.assertEqual(test_heap._heap, [2, 1, 1, 0], "Heap does not contain" "assigned value")
def test_resultant_list(self): input_list = [2, 3, 1, 4] heap = main.Heap(input_list) heap.remove_top() self.assertEqual(heap._heap, [3, 2, 1])
def test_removal_from_empty_heap(self): heap = main.Heap() with self.assertRaises(main.HeapEmptyException, msg="Attempt to Remove top of empty heap"): heap.remove_top()
def test_remove_top_empty(self): heap = ex9_code.Heap() with self.assertRaises(ex9_code.HeapEmptyError): heap.remove_top()
def test_is_empty_false(self): heap = ex9_code.Heap([4]) self.assertFalse(heap.is_empty())
def test_remove_top(self): heap = ex9_code.Heap([4, 3, 2, 1]) heap.remove_top() self.assertEqual(heap._heap, [3, 1, 2])
def test_violates_false(self): heap = ex9_code.Heap([6, 43, 7, 2, 5, 7]) self.assertFalse(heap._violates(2))
def test_init_one_element(self): heap = ex9_code.Heap([5]) self.assertEqual(heap._heap, [5])
def test_bubble_down_large_right(self): heap = ex9_code.Heap() heap._heap = [0, 9, 8, 7, 6, 4, 2, 1, 3] heap._bubble_down(0) self.assertEqual(heap._heap, [9, 7, 8, 3, 6, 4, 2, 1, 0])
def test_bubble_down_large_left(self): heap = ex9_code.Heap() heap._heap = [1, 9, 8, 7, 6, 5, 4, 3] heap._bubble_down(0) self.assertEqual(heap._heap, [9, 7, 8, 3, 6, 5, 4, 1])
def test_small_bubble_down(self): heap = ex9_code.Heap() heap._heap = [1, 3] heap._bubble_down(0) self.assertEqual(heap._heap, [3, 1])
def test_init_blank(self): heap = ex9_code.Heap() self.assertEqual(heap._heap, [])
def test_bubble_up_deep_right_node(self): heap = ex9_code.Heap() heap._heap = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, 11] heap._bubble_up(14) self.assertEqual(heap._heap, [11, 9, 10, 7, 6, 5, 8, 3, 2, 1, 0, -1, -2, -3, 4])
def test_violates_true(self): heap = ex9_code.Heap() heap._heap = [2, 3] self.assertTrue(heap._violates(0))
def test_init_preset(self): heap = ex9_code.Heap([1, 2, 3, 4, 5]) self.assertEqual(heap._heap, [5, 4, 2, 1, 3])
def test_one_element_violates(self): heap = ex9_code.Heap([5]) self.assertFalse(heap._violates(0))
def test_init_no_fixing(self): heap = ex9_code.Heap([5, 4, 2, 1, 3]) self.assertEqual(heap._heap, [5, 4, 2, 1, 3])
def test_remove_top_big_tree(self): heap = ex9_code.Heap([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) heap.remove_top() self.assertEqual(heap._heap, [9, 7, 8, 3, 6, 5, 4, 1, 2])
def test_bubble_up_doing_nothing(self): heap = ex9_code.Heap([3, 2]) heap._bubble_up(1) self.assertEqual(heap._heap, [3, 2])
def test_remove_top_one_element(self): heap = ex9_code.Heap([5]) heap.remove_top() self.assertEqual(heap._heap, [])
def test_bubble_up(self): heap = ex9_code.Heap() heap._heap = [2, 3] heap._bubble_up(1) self.assertEqual(heap._heap, [3, 2])
def test_if_empty(self): # creates an empty heap heap = main.Heap() self.assertTrue(heap.is_empty())
def test_double_bubble_up(self): heap = ex9_code.Heap() heap._heap = [3, 1, 2, 4] heap._bubble_up(3) self.assertEqual(heap._heap, [4, 3, 2, 1])
def test_result(self): input_list = [5, 4, 3, 2] heap = main.Heap(input_list) self.assertEqual(heap.remove_top(), input_list[0])
def test_is_empty_true(self): heap = ex9_code.Heap() self.assertTrue(heap.is_empty())
def test_set_init_values(self): input_list = [4, 2, 3, 5] heap = main.Heap(input_list) self.assertEqual(heap._heap, [5, 4, 3, 2])
def test_bubble_up_deep_left_node(self): heap = ex9_code.Heap() heap._heap = [10, 9, 8, 7, 6, 5, 4, 11] heap._bubble_up(7) self.assertEqual(heap._heap, [11, 10, 8, 9, 6, 5, 4, 7])