Example #1
0
        public void BinaryTreeMergeTime_1000_Test()
        {
            var list      = new List <int>();
            var firstTree = new RedBlackBinaryTree <int>();

            for (var i = 0; i < 500; i++)
            {
                firstTree.Add(i);
                list.Add(i);
            }

            var secondTree = new RedBlackBinaryTree <int>();

            for (var i = 500; i < 1000; i++)
            {
                firstTree.Add(i);
                list.Add(i);
            }

            firstTree.MergeWith(secondTree);

            CollectionAssert.AreEqual(list,
                                      firstTree.Inorder()
                                      .ToArray());
        }
Example #2
0
        public void BinaryTreeMerge_random_Test()
        {
            var list       = new List <int>();
            var rnd        = new Random();
            var firstTree  = new RedBlackBinaryTree <int>();
            var secondTree = new RedBlackBinaryTree <int>();

            for (var i = 0; i < 500; i++)
            {
                var num = rnd.Next(-50, 50);
                firstTree.Add(num);
                list.Add(num);
            }

            for (var i = 500; i < 1000; i++)
            {
                var num = rnd.Next(-50, 50);
                firstTree.Add(num);
                list.Add(num);
            }

            firstTree.MergeWith(secondTree);

            list = list.Distinct()
                   .ToList();

            list.Sort();

            CollectionAssert.AreEqual(list,
                                      firstTree.Inorder()
                                      .ToArray());
        }
Example #3
0
        public void BinaryTree_RemoveTest()
        {
            var tree = new RedBlackBinaryTree <int>();

            for (var i = 0; i < 10; i++)
            {
                tree.Add(i);
            }

            tree.Remove(5);

            CollectionAssert.AreEqual(tree.Inorder()
                                      .ToArray(),
                                      new[]
            {
                0,
                1,
                2,
                3,
                4,
                6,
                7,
                8,
                9
            });
        }
Example #4
0
        public void BinaryTreeMergeTest()
        {
            var firstTree = new RedBlackBinaryTree <int>();

            for (var i = 0; i < 10; i++)
            {
                firstTree.Add(i);
            }

            var secondTree = new RedBlackBinaryTree <int>();

            for (var i = 10; i < 20; i++)
            {
                firstTree.Add(i);
            }

            firstTree.MergeWith(secondTree);

            var checkArray = new[]
            {
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                16,
                17,
                18,
                19
            };

            CollectionAssert.AreEqual(checkArray,
                                      firstTree.Inorder()
                                      .ToArray());
        }
Example #5
0
        public void BinaryTree_Inorder_10000_test()
        {
            var rnd = new Random();

            var numbers = Enumerable.Range(0, 10000)
                          .Select(x => rnd.Next(-30, 30))
                          .Distinct()
                          .ToArray();

            var tree          = new RedBlackBinaryTree <int>(numbers);
            var sortedNumbers = numbers.ToList();

            sortedNumbers.Sort();

            var inorder = tree.Inorder()
                          .ToArray();

            CollectionAssert.AreEqual(inorder, sortedNumbers);
        }
Example #6
0
 public void RedBlackBinaryTreeInorder() => _redBlack.Inorder();