示例#1
0
        public void FindMaxMin_CheckValue()
        {
            ITree tree = new RBTree();

            for (int i = 0; i < Nodes.Length; i++)
            {
                tree.AddNode(Nodes[i]);
            }
            Assert.AreEqual(26, tree.MaxNode().Value);
            Assert.AreEqual(19, tree.MinNode().Value);
        }
示例#2
0
        public void GetColorNodeByKey_CheckColor()
        {
            ITree tree = new RBTree();

            for (int i = 0; i < Nodes.Length; i++)
            {
                tree.AddNode(Nodes[i]);
            }
            Assert.AreEqual(Color.R, tree.GetColorNodeByKey(19));
            Assert.AreEqual(Color.B, tree.GetColorNodeByKey(23));
            Assert.AreEqual(Color.B, tree.GetColorNodeByKey(20));
            Assert.AreEqual(Color.B, tree.GetColorNodeByKey(26));
        }
示例#3
0
        public void FindNextPrev_CheckValue()
        {
            ITree tree = new RBTree();

            for (int i = 0; i < Nodes.Length; i++)
            {
                tree.AddNode(Nodes[i]);
            }
            Assert.AreEqual(20, tree.FindNextNode(19).Value);
            Assert.AreEqual(19, tree.FindPrevNode(20).Value);
            Assert.AreEqual(null, tree.FindPrevNode(19));
            Assert.AreEqual(26, tree.FindNextNode(23).Value);
            Assert.AreEqual(20, tree.FindPrevNode(23).Value);
        }
示例#4
0
        public void AddNode_CheckValue()
        {
            SetExpectedRoot();
            ITree tree = new RBTree();

            for (int i = 0; i < Nodes.Length; i++)
            {
                tree.AddNode(Nodes[i]);
            }
            var result = tree.Root;

            Assert.AreEqual(ExpectedRoot.Left.Value, result.Left.Value);
            Assert.AreEqual(ExpectedRoot.Right.Value, result.Right.Value);
            Assert.AreEqual(ExpectedRoot.Left.Left.Value, result.Left.Left.Value);
            Assert.AreEqual(ExpectedRoot.Value, result.Value);
        }
示例#5
0
        public void RemoveNode_NewRoot_CheckNullParent()
        {
            ITree tree = new RBTree();

            int[] nodes = { 25, 8, 52, 46, 22, 78 };
            for (int i = 0; i < nodes.Length; i++)
            {
                tree.AddNode(nodes[i]);
            }
            tree.RemoveNode(25);
            Assert.AreEqual(null, tree.Root.Parent);
            Assert.AreEqual(22, tree.Root.Value);
            tree.RemoveNode(22);
            Assert.AreEqual(null, tree.Root.Parent);
            Assert.AreEqual(52, tree.Root.Value);
            tree.RemoveNode(52);
            Assert.AreEqual(null, tree.Root.Parent);
            Assert.AreEqual(46, tree.Root.Value);
            tree.RemoveNode(46);
            Assert.AreEqual(null, tree.Root.Parent);
            Assert.AreEqual(8, tree.Root.Value);
        }