def test_delete_node_deletes_a_node_with_no_children_right(): root_node = BinaryTreeNode(5) child_node = BinaryTreeNode(7) tree = BinaryTree(root_node) tree.insert_node(child_node) tree.delete_node(7) assert root_node.get_right() == None
def test_delete_node_sets_parent_nodes_right_to_nodes_left_when_only_left(): root_node = BinaryTreeNode(5) child_node = BinaryTreeNode(7) test_node = BinaryTreeNode(6) tree = BinaryTree(root_node) tree.insert_node(child_node) tree.insert_node(test_node) tree.delete_node(7) assert root_node.get_right() == test_node assert test_node.get_parent() == root_node
def test_delete_node_sets_node_to_minimum(): root_node = BinaryTreeNode(5) child_node = BinaryTreeNode(3) left_node = BinaryTreeNode(2) right_node = BinaryTreeNode(4) tree = BinaryTree(root_node) tree.insert_node(child_node) tree.insert_node(left_node) tree.insert_node(right_node) tree.delete_node(3) assert root_node.get_left().get_value() == 4 assert root_node.get_left() == child_node assert child_node.get_value() == 4 assert child_node.get_right() is None assert child_node.get_left() == left_node assert left_node.get_parent() == child_node assert left_node.get_value() == 2 assert left_node.get_parent().get_value() == 4