コード例 #1
0
        public void Foreach_AddedManyRandomElements_ShouldReturnSortedAscending()
        {
            const int NumCount = 10000;
            var       tree     = new AvlTree <int>();
            var       nums     = new HashSet <int>();
            var       random   = new Random();

            for (int i = 0; i < NumCount; i++)
            {
                var num = random.Next(0, NumCount);
                nums.Add(num);
                tree.Add(num);
            }

            var sortedNumbers    = nums.OrderBy(n => n).ToArray();
            var expectedSequence = new Queue <int>(sortedNumbers);

            int count = 0;

            tree.ForeachDfs((depth, num) =>
            {
                Assert.AreEqual(expectedSequence.Dequeue(), num);
                count++;
            });

            Assert.AreEqual(count, tree.Count);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ivan4otopa/SoftUni
        static void Main(string[] args)
        {
            var tree = new AvlTree<int>();
            var random = new Random();

            for (int i = 0; i < 20; i++)
            {
                var num = random.Next(0, 1000);

                tree.Add(num);
            }

            tree.ForeachDfs((depth, num) =>
            {
                Console.WriteLine(num);
            });
        }
コード例 #3
0
        public void AddingMultipleItems_InBalancedWay_ShouldForeachInOrder()
        {
            var numbers = TestUtils.ToIntArray("20 10 30 0 15 25 40");
            var tree    = new AvlTree <int>();

            foreach (int number in numbers)
            {
                tree.Add(number);
            }

            var sortedNumbers    = numbers.OrderBy(n => n).ToArray();
            var expectedSequence = new Queue <int>(sortedNumbers);

            tree.ForeachDfs((depth, num) =>
            {
                Assert.AreEqual(expectedSequence.Dequeue(), num);
            });
        }
コード例 #4
0
        public void AddingMultipleItems_RandomOrder_ShouldForeachInOrder()
        {
            var nums = TestUtils.ToIntArray("1 5 3 20 6 13 40 70 100 200 -50");

            var tree = new AvlTree <int>();

            foreach (var num in nums)
            {
                tree.Add(num);
            }

            var sortedNumbers    = nums.OrderBy(n => n).ToArray();
            var expectedSequence = new Queue <int>(sortedNumbers);

            tree.ForeachDfs((depth, num) =>
            {
                Assert.AreEqual(expectedSequence.Dequeue(), num);
            });
        }
コード例 #5
0
        public void AddingMultipleItems_RandomOrder_ShouldForeachInOrder()
        {
            var nums = TestUtils.ToIntArrayUnique("1 5 3 20 6 13 40 70 100 200 -50");

            var tree = new AvlTree<int>();
            foreach (var num in nums)
            {
                tree.Add(num);
            }

            var sortedNumbers = nums.OrderBy(n => n).ToArray();
            var expectedSequence = new Queue<int>(sortedNumbers);

            int count = 0;
            tree.ForeachDfs((depth, num) =>
            {
                Assert.AreEqual(expectedSequence.Dequeue(), num);
                count++;
            });

            Assert.AreEqual(count, tree.Count);
        }
コード例 #6
0
        public void AddingMultipleItems_InBalancedWay_ShouldForeachInOrder()
        {
            var numbers = TestUtils.ToIntArrayUnique("20 10 30 0 15 25 40");
            var tree = new AvlTree<int>();

            foreach (int number in numbers)
            {
                tree.Add(number);
            }

            var sortedNumbers = numbers.OrderBy(n => n).ToArray();
            var expectedSequence = new Queue<int>(sortedNumbers);

            int count = 0;
            tree.ForeachDfs((depth, num) =>
            {
                Assert.AreEqual(expectedSequence.Dequeue(), num);
                count++;
            });

            Assert.AreEqual(count, tree.Count);
        }
コード例 #7
0
        public void Foreach_AddedManyRandomElements_ShouldReturnSortedAscending()
        {
            const int NumCount = 10000;
            var tree = new AvlTree<int>();
            var nums = new HashSet<int>();
            var random = new Random();
            for (int i = 0; i < NumCount; i++)
            {
                var num = random.Next(0, NumCount);
                nums.Add(num);
                tree.Add(num);
            }

            var sortedNumbers = nums.OrderBy(n => n).ToArray();
            var expectedSequence = new Queue<int>(sortedNumbers);

            int count = 0;
            tree.ForeachDfs((depth, num) =>
            {
                Assert.AreEqual(expectedSequence.Dequeue(), num);
                count++;
            });

            Assert.AreEqual(count, tree.Count);
        }