public void CanEnumerateBreadthFirstSearch()
        {
            var tree = new BinarySearchTree<int, int>(new[] {3, 2, 1, 2, 4, 3}.AsKeyValueList());

            var expected = new[] {3, 2, 4, 1, 2, 3};
            CollectionAssert.AreEqual(expected, tree.BreadthFirstSearchEnumerator().Select(_ => _.Value).ToList());
        }
        public void AppearInRootAfterAddingFirstElement()
        {
            var tree = new BinarySearchTree<int, int>();
            var element = 1.AsKeyValue();
            tree.Insert(element);

            Assert.IsTrue(tree.BreadthFirstSearchEnumerator().Contains(element));
            Assert.IsTrue(tree.DepthFirstSearchEnumerator().Contains(element));
        }
        public void CanDeleteFromMiddleWithRightChild()
        {
            var tree = new BinarySearchTree<int, int>();
            tree.Insert(1.AsKeyValue());
            tree.Insert(2.AsKeyValue());
            tree.Insert(3.AsKeyValue());

            tree.Delete(2);

            CollectionAssert.AreEqual(new[] {1, 3}, tree.BreadthFirstSearchEnumerator().Select(_ => _.Value).ToList());
        }
        public void CanDeleteFromLeftLeaf()
        {
            var tree = new BinarySearchTree<int, int>();
            tree.Insert(3.AsKeyValue());
            tree.Insert(2.AsKeyValue());
            tree.Insert(1.AsKeyValue());

            tree.Delete(1);

            CollectionAssert.AreEqual(new[] {3, 2}, tree.BreadthFirstSearchEnumerator().Select(_ => _.Value).ToList());
        }
        public void CountInEnumeratorsMustMatchCountInTree()
        {
            var tree = new BinarySearchTree<int, int>();

            tree.Insert(1.AsKeyValue());
            tree.Insert(3.AsKeyValue());
            tree.Insert(2.AsKeyValue());

            Assert.AreEqual(3, tree.BreadthFirstSearchEnumerator().Count());
            Assert.AreEqual(3, tree.DepthFirstSearchEnumerator().Count());
        }
        public void AppearInBinarySerachTreeOrder()
        {
            var tree = new BinarySearchTree<int, int>();
            var element1 = 1.AsKeyValue();
            var element2 = 2.AsKeyValue();
            var element3 = 3.AsKeyValue();
            tree.Insert(element2);
            tree.Insert(element3);
            tree.Insert(element1);

            var elements = tree.BreadthFirstSearchEnumerator();
            Assert.AreEqual(elements.ElementAt(0), element2);
            Assert.AreEqual(elements.ElementAt(1), element1);
            Assert.AreEqual(elements.ElementAt(2), element3);
        }