示例#1
0
        public void ReturnSameIfNotFound()
        {
            var solution = new DeleteNodeInBST();

            var tree  = new TreeNode(3);
            var clone = tree.Clone();

            Assert.AreEqual(clone, solution.DeleteNode(tree, 0));

            Assert.AreEqual(clone, solution.DeleteNode(tree, 5));
        }
示例#2
0
        public void ShouldRemoveLeafNode()
        {
            var solution = new DeleteNodeInBST();

            Assert.AreEqual(
                new TreeNode(3),
                solution.DeleteNode(new TreeNode(3, new TreeNode(2)), 2));

            Assert.AreEqual(
                new TreeNode(3),
                solution.DeleteNode(new TreeNode(3, null, new TreeNode(5)), 5));
        }
示例#3
0
        public void ShouldRemoveNonLeafNode()
        {
            var solution = new DeleteNodeInBST();

            var tree = new TreeNode(
                5,
                new TreeNode(3, new TreeNode(2), new TreeNode(4)),
                new TreeNode(6, null, new TreeNode(7)));

            var deleted   = solution.DeleteNode(tree, 3);
            var expected1 = new TreeNode(
                5,
                new TreeNode(2, null, new TreeNode(4)),
                new TreeNode(6, null, new TreeNode(7)));

            var expected2 = new TreeNode(
                5,
                new TreeNode(4, new TreeNode(2)),
                new TreeNode(6, null, new TreeNode(7)));

            Assert.IsTrue(deleted.Equals(expected1) || deleted.Equals(expected2));
        }