예제 #1
0
        public void LRWithSubtreesAtRight_ShouldLeftRightRotate()
        {
            //Arrange
            IBinarySearchTree <int> tree = new AVLTree <int>(DataComparers.NewByType <int>());

            tree = tree.AddNode(30);
            tree = tree.AddNode(10);
            tree = tree.AddNode(20);
            tree = tree.AddNode(15);
            tree = tree.AddNode(25);

            //Act
            Assert.Equal(20, tree.Value);
            Assert.Equal(3, tree.Height);

            Assert.Equal(10, tree.Left.Value);
            Assert.Equal(2, tree.Left.Height);

            Assert.Equal(15, tree.Left.Right.Value);
            Assert.Equal(1, tree.Left.Right.Height);

            Assert.Equal(30, tree.Right.Value);
            Assert.Equal(2, tree.Right.Height);

            Assert.Equal(25, tree.Right.Left.Value);
            Assert.Equal(1, tree.Right.Left.Height);
        }