Пример #1
0
        public void BinaryTreeUnbalancedDelete12()
        {
            List <int> input = new List <int>()
            {
                1, 18, 17, 13, 16, 10, 7, 15, 9, 6, 3, 2, 24, 25, 8, 12, 11, 4, 14, 21, 23, 5, 20, 19, 22
            };
            UnbalancedBinaryTree <int, int> tree = new UnbalancedBinaryTree <int, int>();

            foreach (int i in input)
            {
                tree.Add(i, i);
            }
            List <int> deletes = new List <int>()
            {
                1, 6, 18, 25, 2
            };
            int count = input.Count;

            foreach (int i in deletes)
            {
                Console.WriteLine("Removing Key " + i);
                Assert.IsTrue(tree.Remove(i), "Failed to remove Key " + i);
                input.Remove(i);
                count--;
                this.TestOrderStructs <int>(input.OrderBy(k => k, Comparer <int> .Default).ToList(), tree.Keys.ToList());
                Assert.AreEqual(count, tree.Nodes.Count(), "Removal of Key " + i + " did not reduce node count as expected");
            }
        }
Пример #2
0
        public void BinaryTreeUnbalancedDelete5()
        {
            UnbalancedBinaryTree <int, int> tree = new UnbalancedBinaryTree <int, int>();
            List <int> inputs = Enumerable.Range(1, 100).ToList();

            this.TestOrderPreservationOnInsertStructs <IBinaryTreeNode <int, int>, int>(inputs, tree);
            Assert.IsTrue(tree.Remove(inputs[50]));
            inputs.RemoveAt(50);
            this.TestOrderStructs <int>(inputs, tree.Keys.ToList());
        }
Пример #3
0
        public void BinaryTreeUnbalancedDelete3()
        {
            UnbalancedBinaryTree <int, int> tree = this.GetTreeForDelete();

            BinaryTreeTools.PrintBinaryTreeStructs <IBinaryTreeNode <int, int>, int>(tree);
            tree.Remove(2);
            BinaryTreeTools.PrintBinaryTreeStructs <IBinaryTreeNode <int, int>, int>(tree);

            this.TestOrderStructs <int>(new List <int> {
                1, 3
            }, tree.Keys.ToList());
        }
Пример #4
0
        public void BinaryTreeUnbalancedDelete2()
        {
            UnbalancedBinaryTree <int, int> tree = this.GetTreeForDelete();

            BinaryTreeTools.PrintBinaryTreeStructs <IBinaryTreeNode <int, int>, int>(tree);
            tree.Remove(3);
            BinaryTreeTools.PrintBinaryTreeStructs <IBinaryTreeNode <int, int>, int>(tree);
            Assert.IsNull(tree.Root.RightChild, "Right Child should now be null");

            this.TestOrderStructs <int>(new List <int> {
                1, 2
            }, tree.Keys.ToList());
        }