示例#1
0
        public void ConverBST_EmptyTree_ShouldReturnNull()
        {
            TreeNode tree = null;

            var result = ConvertBSTImplementation.ConvertBST(tree);

            Assert.Null(result);
        }
示例#2
0
        public void ConverBST_RootTree_ShouldReturnRootTree()
        {
            TreeNode tree = new TreeNode(5);

            var result = ConvertBSTImplementation.ConvertBST(tree);

            Assert.Null(result.left);
            Assert.Null(result.right);
            Assert.Equal(5, tree.val);
        }
示例#3
0
        public void ConvertBST_FromLeetCode_ShouldConvertToGreaterTree()
        {
            var tree = new TreeNode(5);

            tree.left  = new TreeNode(2);
            tree.right = new TreeNode(13);
            var expectedResult = new TreeNode(18);

            expectedResult.left  = new TreeNode(20);
            expectedResult.right = new TreeNode(13);

            var result = ConvertBSTImplementation.ConvertBST(tree);

            Assert.True(expectedResult.Equals(result) && result.Equals(expectedResult));
        }
示例#4
0
        public void ConvertBST_FailedUseCase_ShouldConvertToGreaterTree()
        {
            var tree = new TreeNode(2);

            tree.left       = new TreeNode(0);
            tree.left.left  = new TreeNode(-4);
            tree.left.right = new TreeNode(1);
            tree.right      = new TreeNode(3);
            var expectedResult = new TreeNode(5);

            expectedResult.left       = new TreeNode(6);
            expectedResult.left.left  = new TreeNode(2);
            expectedResult.left.right = new TreeNode(6);
            expectedResult.right      = new TreeNode(3);

            var result = ConvertBSTImplementation.ConvertBST(tree);

            Assert.True(result.Equals(expectedResult) && expectedResult.Equals(result));
        }