コード例 #1
0
    def test_4(self):
        postorder = [1]
        inorder = [1]
        act_bt = Solution().buildTree(inorder, postorder)

        exp_tree = TreeNode(1)

        self.assertTrue(TU.is_equal_trees(exp_tree, act_bt))
コード例 #2
0
    def test_equal_4(self):
        r1 = TreeNode(0)
        r1.left = TreeNode(1)
        r1.right = TreeNode(2)

        r2 = TreeNode(0)
        r2.left = TreeNode(1)
        r2.right = TreeNode(1)

        self.assertFalse(TU.is_equal_trees(r1, r2))
コード例 #3
0
    def test_1(self):
        inorder = [9, 3, 15, 20, 7]
        postorder = [9, 15, 7, 20, 3]
        act_bt = Solution().buildTree(inorder, postorder)

        r = TreeNode(3)
        r.left = TreeNode(9)
        r.right = TreeNode(20)
        r.right.left = TreeNode(15)
        r.right.right = TreeNode(7)

        self.assertTrue(TU.is_equal_trees(r, act_bt))
コード例 #4
0
    def test_equal_5(self):
        r1 = TreeNode(0)
        r1.left = TreeNode(1)
        r1.right = TreeNode(2)
        r1.left.left = TreeNode(3)
        r1.right.right = TreeNode(0)

        r2 = TreeNode(0)
        r2.left = TreeNode(1)
        r2.left.left = TreeNode(3)
        r2.right = TreeNode(2)
        r2.right.right = TreeNode(0)

        self.assertTrue(TU.is_equal_trees(r1, r2))
コード例 #5
0
 def test_equal_2(self):
     r1 = TreeNode(0)
     r2 = TreeNode(0)
     self.assertTrue(TU.is_equal_trees(r1, r2))
コード例 #6
0
 def test_equal_1(self):
     root1 = TreeNode(0)
     self.assertTrue(TU.is_equal_trees(root1, root1))
コード例 #7
0
 def test_equal_0(self):
     root1 = TreeNode(0)
     root2 = None
     self.assertFalse(TU.is_equal_trees(root1, root2))
コード例 #8
0
    def test_3(self):
        postorder = []
        inorder = [9, 15, 7, 20, 3]
        act_bt = Solution().buildTree(inorder, postorder)

        self.assertTrue(TU.is_equal_trees(None, act_bt))