Esempio n. 1
0
        public void TestRightRotationOnRoot()
        {
            TestContext.Progress.WriteLine("Test right rotation centered on root:");

            tree.Root = new RbTree <int> .Node(10, tree.Nil);

            tree.Root.Left = new RbTree <int> .Node(5, tree.Root);

            Assert.AreEqual(10, tree.Root.Key);
            Assert.AreEqual(5, tree.Root.Left.Key);
            Assert.AreEqual(RbTree <int> .Node.Leaf(), tree.Root.Right);
            TestContext.Progress.WriteLine("    Before rotation:");
            TestContext.Progress.WriteLine(
                $"        Root: {tree.Root}, Right: {tree.Root.Right}, Left: {tree.Root.Left}");

            tree.RightRotate(tree.Root);
            TestContext.Progress.WriteLine("    After rotation:");

            TestContext.Progress.WriteLine(
                $"        Root: {tree.Root}, Right: {tree.Root.Right}, Left: {tree.Root.Left}");
            Assert.AreEqual(5, tree.Root.Key);
            Assert.AreEqual(10, tree.Root.Right.Key);
        }