Exemplo n.º 1
0
        public void TestLeftRotationOnRoot()
        {
            TestContext.Progress.WriteLine("Test left rotation centered on root:");
            tree.Root = new RbTree <int> .Node(5, tree.Nil);

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

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

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