def setUp(self):
     self.solution = Solution()
     self.tree_root = TreeNode(3)
     self.tree_root.left = TreeNode(9)
     self.tree_root.right = TreeNode(20)
     self.tree_root.right.left = TreeNode(15)
     self.tree_root.right.right = TreeNode(7)
예제 #2
0
    def test_rightSideView_dfs1(self):
        node_root = TreeNode(1)
        node_root.left = TreeNode(2)
        node_root.left.right = TreeNode(5)

        right_side_view_list = self.solution.rightSideView_dfs(node_root)
        self.assertIsNotNone(right_side_view_list)
        self.assertEqual(3, len(right_side_view_list))
        self.assertEqual(1, right_side_view_list[0])
        self.assertEqual(2, right_side_view_list[1])
        self.assertEqual(5, right_side_view_list[2])
예제 #3
0
    def test_rightSideView_dfs_root(self):
        node_root = TreeNode(1)

        right_side_view_list = self.solution.rightSideView_dfs(node_root)
        self.assertIsNotNone(right_side_view_list)
        self.assertEqual(1, len(right_side_view_list))
        self.assertEqual(1, right_side_view_list[0])
예제 #4
0
    def setUp(self):
        self.solution = Solution()

        self.tree_alpha_root_node = TreeNode(2)
        self.tree_alpha_root_node.left = TreeNode(1)
        self.tree_alpha_root_node.right = TreeNode(3)

        self.tree_beta_root_node = TreeNode(5)
        self.tree_beta_root_node.left = TreeNode(1)
        self.tree_beta_root_node.right = TreeNode(4)
        self.tree_beta_root_node.right.left = TreeNode(3)
        self.tree_beta_root_node.right.right = TreeNode(6)

        self.tree_maxint_alpha_root_node = TreeNode(maxint - 1)
        self.tree_maxint_alpha_root_node.left = TreeNode(maxint - 2)
        self.tree_maxint_alpha_root_node.right = TreeNode(maxint)

        minint = - maxint - 1
        self.tree_minint_alpha_root_node = TreeNode(minint + 1)
        self.tree_minint_alpha_root_node.left = TreeNode(minint)
        self.tree_minint_alpha_root_node.right = TreeNode(minint + 2)
예제 #5
0
    def test_rightSideView_dfs_none(self):
        node_root = TreeNode(1)

        right_side_view_list = self.solution.rightSideView_dfs(None)
        self.assertIsNone(right_side_view_list)
예제 #6
0
    def test_lowestCommonAncestorBST(self):
        node_root = TreeNode(6)
        node_root.left = TreeNode(2)
        node_root.left.left = TreeNode(0)
        node_root.left.right = TreeNode(4)
        node_root.left.right.left = TreeNode(3)
        node_root.left.right.right = TreeNode(5)
        node_root.right = TreeNode(8)
        node_root.right.left = TreeNode(7)
        node_root.right.right = TreeNode(9)

        lca = self.solution.lowestCommonAncestorBST(node_root, node_root.left, node_root.right)
        self.assertIsNotNone(lca)
        self.assertEqual(node_root, lca)
 def test_maxDepth_instinct_leaf_root(self):
     root_leaf = TreeNode(0)
     tree_depth = self.solution.maxDepth_instinct(root_leaf)
     self.assertEqual(1, tree_depth)
 def test_minDepth_recursion_leaf_root(self):
     leaf_root = TreeNode(1)
     min_depth = self.solution.minDepth_recursion(leaf_root)
     self.assertIsNotNone(min_depth)
     self.assertEqual(1, min_depth)