def test_height(self): # Create node with no children node = BinaryTreeNode(2) assert node.height() == 0 # Attach left child node node.left = BinaryTreeNode(1) assert node.height() == 1 # Attach right child node node.right = BinaryTreeNode(3) assert node.height() == 1 # Attach right child node to right node child node.right.right = BinaryTreeNode(5) assert node.height() == 2 # Attach right child node to previously attached right node child node.right.right.right = BinaryTreeNode(7) assert node.height() == 3 # Detach right leaf node node.right.right.right = None assert node.height() == 2 # Detach right leaf node again node.right.right = None assert node.height() == 1 # Detach left child node node.left = None assert node.height() == 1 # Detach right child node node.right = None assert node.height() == 0
def test_height(self): second_child_node = BinaryTreeNode(7) second_child_node.right = BinaryTreeNode(8) child_node = BinaryTreeNode(1) child_node.left = second_child_node child_node.right = BinaryTreeNode(6) node = BinaryTreeNode(2) node.right = BinaryTreeNode(3) assert node.height() == 1 node.left = child_node assert node.height() == 3
def test_height(self): # Create node with no children node = BinaryTreeNode(2) assert node.height() == 0 # Add child node.left = BinaryTreeNode(1) assert node.height() == 1 # Add grandchild on left side node.left.right = BinaryTreeNode(4) assert node.height() == 2
def test_height(self): left_node = BinaryTreeNode(3) root_node = BinaryTreeNode(5) right_node = BinaryTreeNode(8) root_node.left = left_node root_node.right = right_node left_node_of_left = BinaryTreeNode(2) right_node_of_Left = BinaryTreeNode(4) left_node.left = left_node_of_left left_node.right = right_node_of_Left left_node_of_left_node_of_left = BinaryTreeNode(1) left_node_of_left.left = left_node_of_left_node_of_left right_node_right = BinaryTreeNode(9) right_node.right = right_node_right assert root_node.height() == 3
def test_height(self): # Create node with no children node = BinaryTreeNode(4) assert node.height() == 0 # Attach left child node node.left = BinaryTreeNode(2) assert node.height() == 1 # Attach right child node node.right = BinaryTreeNode(6) assert node.height() == 1 # Attach left-left grandchild node node.left.left = BinaryTreeNode(1) assert node.height() == 2 # Attach right-right grandchild node node.right.right = BinaryTreeNode(8) assert node.height() == 2 # Attach right-right-left great-grandchild node node.right.right.left = BinaryTreeNode(7) assert node.height() == 3