Пример #1
0
        public void Height_2_RightRight()
        {
            BinarySearchTreeNode<int> root = new BinarySearchTreeNode<int>(100);
            root.Left = new BinarySearchTreeNode<int>(50);
            root.Right = new BinarySearchTreeNode<int>(150);

            root.Right.Right = new BinarySearchTreeNode<int>(160);

            Assert.AreEqual<int>(2, root.Height);
        }
        public void AssertValidTree_InvalidChildren()
        {
            var root = new BinarySearchTreeNode<int>(100);
            root.Left = new BinarySearchTreeNode<int>(150);

            BinarySearchTree<int> bst = new BinarySearchTree<int>();
            bst.Root = root;

            bst.AssertValidTree();
        }
Пример #3
0
        public void Height_2_FullSecondLevel()
        {
            BinarySearchTreeNode<int> root = new BinarySearchTreeNode<int>(100);
            root.Left = new BinarySearchTreeNode<int>(50);
            root.Right = new BinarySearchTreeNode<int>(150);

            root.Left.Left = new BinarySearchTreeNode<int>(40);
            root.Left.Right = new BinarySearchTreeNode<int>(60);
            root.Right.Left = new BinarySearchTreeNode<int>(110);
            root.Right.Right = new BinarySearchTreeNode<int>(160);

            Assert.AreEqual<int>(2, root.Height);
        }
Пример #4
0
        public void Height_3_LeftLeftLeft()
        {
            BinarySearchTreeNode<int> root = new BinarySearchTreeNode<int>(100);
            root.Left = new BinarySearchTreeNode<int>(50);
            root.Right = new BinarySearchTreeNode<int>(150);

            root.Left.Left = new BinarySearchTreeNode<int>(40);
            root.Left.Right = new BinarySearchTreeNode<int>(60);
            root.Right.Left = new BinarySearchTreeNode<int>(110);
            root.Right.Right = new BinarySearchTreeNode<int>(160);

            root.Left.Left.Left = new BinarySearchTreeNode<int>(30);

            Assert.AreEqual<int>(3, root.Height);
        }
Пример #5
0
        public void Height_Root()
        {
            BinarySearchTreeNode<int> root = new BinarySearchTreeNode<int>(100);

            Assert.AreEqual<int>(0, root.Height);
        }
Пример #6
0
        public void ToString_RootRight()
        {
            BinarySearchTreeNode<int> node = new BinarySearchTreeNode<int>(50)
            {
                Right = new BinarySearchTreeNode<int>(75),
            };

            Assert.AreEqual<string>("50; Left=null; Right=75", node.ToString());
        }
Пример #7
0
        public void InOrderSuccessor_RootRightRight()
        {
            BinarySearchTreeNode<int> rootRightRight = new BinarySearchTreeNode<int>(50)
            {
                Right = new BinarySearchTreeNode<int>(75)
                {
                    Right = new BinarySearchTreeNode<int>(100)
                }
            };

            Assert.AreEqual<int>(75, rootRightRight.InOrderSuccessor.Value);
        }
Пример #8
0
        public void InOrderSuccessor_RootLeft()
        {
            BinarySearchTreeNode<int> rootLeft = new BinarySearchTreeNode<int>(50)
            {
                Left = new BinarySearchTreeNode<int>(25)
            };

            Assert.IsNull(rootLeft.InOrderSuccessor);
        }
Пример #9
0
 public void InOrderSuccessor_Leaf()
 {
     BinarySearchTreeNode<int> leaf = new BinarySearchTreeNode<int>(50);
     Assert.IsNull(leaf.InOrderSuccessor);
 }
Пример #10
0
        public void InOrderPredecessor_RootRight()
        {
            BinarySearchTreeNode<int> rootRight = new BinarySearchTreeNode<int>(50)
            {
                Right = new BinarySearchTreeNode<int>(75)
            };

            Assert.IsNull(rootRight.InOrderPredecessor);
        }
Пример #11
0
        public void InOrderPredecessor_RootLeftRight()
        {
            BinarySearchTreeNode<int> rootLeftRight = new BinarySearchTreeNode<int>(50)
            {
                Left = new BinarySearchTreeNode<int>(25)
                {
                    Right = new BinarySearchTreeNode<int>(30)
                }
            };

            Assert.AreEqual<int>(30, rootLeftRight.InOrderPredecessor.Value);
        }
Пример #12
0
        public void Height_RootWithRightChild()
        {
            BinarySearchTreeNode<int> root = new BinarySearchTreeNode<int>(100);
            root.Right = new BinarySearchTreeNode<int>(150);

            Assert.AreEqual<int>(1, root.Height);
        }