예제 #1
0
        public void GivenSearch_WhenZigZag_ThenTreeRotated()
        {
            // Arrange
            var tree = SplayTree <int> .BuildTree(_treeValues);

            // Act
            tree = SplayTree <int> .Splay(tree, 20);

            // Assert
            Assert.Equal(20, tree.Value);
        }
예제 #2
0
        public void GivenSearch_WhenValueIsAtRoot_ThenRootIsUnchanged()
        {
            // Arrange
            var tree = SplayTree <int> .BuildTree(_treeValues);

            // Act
            tree = SplayTree <int> .Splay(tree, 50);

            // Assert
            Assert.Equal(50, tree.Value);
        }
예제 #3
0
        public void GivenSearch_WhenValueNotInTree_ThenClosestNodeReturned()
        {
            // Arrange
            var tree = SplayTree <int> .BuildTree(_treeValues);

            // Act
            tree = SplayTree <int> .Splay(tree, 100);

            // Assert
            Assert.Equal(90, tree.Value);
        }
예제 #4
0
        public void GivenSearch_WhenValueInTree_ThenNodeReturned()
        {
            // Arrange
            var nodeValues = new[] { 100, 50, 40, 30, 20, 200 };
            var tree       = SplayTree <int> .BuildTree(nodeValues);

            // Act
            tree = SplayTree <int> .Splay(tree, 20);

            // Assert
            Assert.Equal(20, tree.Value);
        }
예제 #5
0
        public void GivenSearch_WhenValueIsRightChildOfRoot_ThenTreeRotated()
        {
            // Arrange
            var tree = SplayTree <int> .BuildTree(_treeValues);

            // Act
            tree = SplayTree <int> .Splay(tree, 80);

            // Assert
            Assert.Equal(80, tree.Value);
            Assert.Equal(50, tree.Left.Value);
            Assert.Equal(90, tree.Right.Value);
        }
예제 #6
0
        public void GivenNumberList_ThenCorrectTreeBuild()
        {
            // Arrange
            var tree = SplayTree <int> .BuildTree(_treeValues);

            // Assert
            Assert.Equal(50, tree.Value);
            Assert.Equal(20, tree.Left.Value);
            Assert.Equal(10, tree.Left.Left.Value);
            Assert.Equal(30, tree.Left.Right.Value);
            Assert.Equal(10, tree.Left.Left.Value);
            Assert.Equal(80, tree.Right.Value);
            Assert.Equal(70, tree.Right.Left.Value);
            Assert.Equal(90, tree.Right.Right.Value);
        }