public void SearchForOneNode_WalkThroughTheRightPathNoEmptyValue_BiggestElement()
        {
            var bst = SimpleTree.Create();

            var node = bst.SearchForOneNode(v => Bst.Key.IsBigger, true);

            NodeAssert.NotNullAndEqual(SimpleTree.BiggestElement, node);
        }
        public void SearchForOneNode_AcceptRootElement_RootElement()
        {
            var bst = SimpleTree.Create();

            var node = bst.SearchForOneNode(v => Bst.Key.IsEqual);

            NodeAssert.NotNullAndEqual(SimpleTree.RootElement, node);
        }
        public void Insert_InsertFirstItem_TreeContainsOneItem()
        {
            var firstNode = 1;

            var bst = new BinarySearchTree <int, int>();

            bst.Insert(Key(firstNode), Value(firstNode));

            NodeAssert.NotNullAndEqual(bst.Root, Node(firstNode));
        }
        public void Insert_InsertSecondBiggerItem_TreeContainsTwoItems()
        {
            var firstNode  = 2;
            var secondNode = 3;

            var bst = new BinarySearchTree <int, int>();

            bst.Insert(Key(firstNode), Value(firstNode));
            bst.Insert(Key(secondNode), Value(secondNode));

            NodeAssert.NotNullAndEqual(bst.Root, Node(firstNode));
            NodeAssert.NotNullAndEqual(bst.Root.Right, Node(secondNode));
        }
        public void Remove_TheRightChildWithNoChildren_TheRootWithNoChildren()
        {
            var firstNode  = 2;
            var secondNode = 3;

            var bst = new BinarySearchTree <int, int>();

            bst.Insert(Key(firstNode), Value(firstNode));
            bst.Insert(Key(secondNode), Value(secondNode));

            bst.Remove(Key(secondNode));

            NodeAssert.NotNullAndEqual(bst.Root, Node(firstNode));
            NodeAssert.BothChildrenAreNull(bst.Root);
        }
        public void Remove_TheRootElementWithLeftChild_NewRootIsTheLeftChild()
        {
            var firstNode  = 2;
            var secondNode = 1;

            var bst = new BinarySearchTree <int, int>();

            bst.Insert(Key(firstNode), Value(firstNode));
            bst.Insert(Key(secondNode), Value(secondNode));

            bst.Remove(Key(firstNode));

            NodeAssert.NotNullAndEqual(bst.Root, Node(secondNode));
            NodeAssert.BothChildrenAreNull(bst.Root);
        }
        public void Insert_InsertTwoSamllerItems_TreeContainsTwoItems()
        {
            var firstNode  = 3;
            var secondNode = 2;
            var thirdNode  = 1;

            var bst = new BinarySearchTree <int, int>();

            bst.Insert(Key(firstNode), Value(firstNode));
            bst.Insert(Key(secondNode), Value(secondNode));
            bst.Insert(Key(thirdNode), Value(thirdNode));

            NodeAssert.NotNullAndEqual(bst.Root, Node(firstNode));
            NodeAssert.NotNullAndEqual(bst.Root.Left, Node(secondNode));
            NodeAssert.NotNullAndEqual(bst.Root.Left.Left, Node(thirdNode));
        }
        public void Remove_ANotExistingElementFromATwoLevelTree_TheCorrectTree()
        {
            var notExistingNode = SimpleTree.NotExistingElement;
            var bst             = SimpleTree.Create();

            bst.Remove(notExistingNode.Key);

            NodeAssert.NotNullAndEqual(bst.Root, SimpleTree.RootElement);
            NodeAssert.BothChildrenAreNotNull(bst.Root);

            NodeAssert.NotNullAndEqual(bst.Root.Right, SimpleTree.SecondBiggestElement);
            NodeAssert.BothChildrenAreNotNull(bst.Root.Right);

            NodeAssert.NotNullAndEqual(bst.Root.Left, SimpleTree.SecondSmallestElement);
            NodeAssert.BothChildrenAreNotNull(bst.Root.Left);
        }
        public void Remove_TheRightChildWithLeftChild_TheRootWithWithRightChild()
        {
            var firstNode  = 1;
            var secondNode = 3;
            var thirdNode  = 2;

            var bst = new BinarySearchTree <int, int>();

            bst.Insert(Key(firstNode), Value(firstNode));
            bst.Insert(Key(secondNode), Value(secondNode));
            bst.Insert(Key(thirdNode), Value(thirdNode));

            bst.Remove(Key(secondNode));

            NodeAssert.NotNullAndEqual(bst.Root, Node(firstNode));
            NodeAssert.NotNullAndEqual(bst.Root.Right, Node(thirdNode));
            NodeAssert.LeftChildIsNull(bst.Root);
        }
        public void Remove_TheRootFromAThreeLevelTree_TheCorrectTree()
        {
            var firstNode = Node(9);
            var rootNode  = ComplexTree.RootElement;
            var bst       = ComplexTree.Create();

            bst.Remove(firstNode.Key);
            bst.Remove(rootNode.Key);

            NodeAssert.NotNullAndEqual(bst.Root, Node(10));
            NodeAssert.BothChildrenAreNotNull(bst.Root);

            NodeAssert.NotNullAndEqual(bst.Root.Right, Node(12));
            NodeAssert.BothChildrenAreNotNull(bst.Root.Right);
            NodeAssert.BothChildrenAreNull(bst.Root.Right.Left);
            NodeAssert.BothChildrenAreNotNull(bst.Root.Right.Right);

            NodeAssert.NotNullAndEqual(bst.Root.Left, Node(4));
            NodeAssert.BothChildrenAreNotNull(bst.Root.Left);
            NodeAssert.BothChildrenAreNotNull(bst.Root.Left.Left);
            NodeAssert.BothChildrenAreNotNull(bst.Root.Left.Right);
        }