Пример #1
0
        public void NotFailOnStackOverflow()
        {
            var tree = new BinaryTree <int>();

            foreach (var e in Enumerable.Range(0, 10000))
            {
                tree.Add(e);
                tree.Contains(e);
            }
        }
Пример #2
0
        public void CheckIEnumeratorIsLazy(int size)
        {
            var values = Enumerable.Range(0, size).Shuffle();
            var tree   = new BinaryTree <int>();

            foreach (var e in values)
            {
                tree.Add(e);
            }
            RunWithTimeout(() => IEnumeratorIsLazy(tree), 500, "Your binary tree should be lazy");
        }
        static void Main(string[] args)
        {
            BinaryTree <int> tree = new BinaryTree <int>();

            tree.Add(5);
            tree.Add(6);
            tree.Add(8);
            tree.Add(4);
            tree.Add(3);
            tree.Add(2);
            tree.Add(9);
            tree.Add(1);

            tree.PreOrderTraversalIteratively(tree.GetRoot());

            Console.ReadLine();
        }
Пример #4
0
        private void TestAddContains <T>(IEnumerable <T> values)
            where T : IComparable
        {
            var shuffledValues = values.Shuffle();
            var toAdd          = shuffledValues.Where(z => rnd.NextDouble() > 0.7).ToList();
            var tree           = new BinaryTree <T>();

            foreach (var e in toAdd)
            {
                tree.Add(e);
            }
            foreach (var e in shuffledValues)
            {
                Assert.AreEqual(toAdd.Contains(e), tree.Contains(e));
            }
        }
Пример #5
0
        public void TestIEnumerable <T>(IEnumerable <T> _values)
            where T : IComparable
        {
            var values        = _values.Shuffle();
            var orderedValues = values.OrderBy(z => z).ToList();
            var tree          = new BinaryTree <T>();

            foreach (var e in values)
            {
                tree.Add(e);
            }

            // ReSharper disable once IsExpressionAlwaysTrue
            Assert.True(tree is IEnumerable <T>, "Your binary tree does not implement IEnumerable");
            var en = (IEnumerable <T>)tree;

            Assert.AreEqual(orderedValues, en.ToList());
        }
Пример #6
0
        public void TestIEnumerable <T>(IEnumerable <T> _values)
            where T : IComparable
        {
            var values        = _values.Shuffle();
            var orderedValues = values.OrderBy(z => z).ToList();
            var tree          = new BinaryTree <T>();

            foreach (var e in values)
            {
                tree.Add(e);
            }



            Assert.True(tree is IEnumerable <T>, "You binary tree does not implement IEnumerable");
            var en = tree as IEnumerable <T>;

            Assert.AreEqual(orderedValues, en.ToList());
        }
Пример #7
0
        public void Test <T>(IEnumerable <T> values)
            where T : IComparable
        {
            var shuffledValues = values.Shuffle();
            var tree           = new BinaryTree <T>();

            if (GetIndexer(tree) == null)
            {
                Assert.Fail("Your BinaryTree does not implement indexing");
            }
            foreach (var e in shuffledValues)
            {
                tree.Add(e);
            }
            var orderedValues = shuffledValues.OrderBy(z => z).ToList();
            var indexer       = MakeAccessor(tree);

            for (int i = 0; i < orderedValues.Count; i++)
            {
                Assert.AreEqual(orderedValues[i], indexer(i));
            }
        }