Ejemplo n.º 1
0
        public void TestModificationsList()
        {
            var rand = new Random(0);
            var list = new RedBlackList <int> {
                Enumerable.Range(0, 1000).Select(i => i * 100)
            };

            for (int i = 0; i < 100; i++)
            {
                bool insert = list.Count < 100 || list.Count < 2000 && rand.Next(2) == 0;
                int  n      = rand.Next(1, insert ? list.Count : list.Count / 2);
                for (int j = 0; j < n; j++)
                {
                    if (insert)
                    {
                        int r = rand.Next(list.Count + 1);
                        int a = r == 0 ? int.MinValue : list[r - 1] + 1;
                        int b = r == list.Count ? int.MaxValue : list[r];
                        if (a == b)
                        {
                            continue;
                        }

                        list.Insert(rand.Next(a, b));
                    }
                    else
                    {
                        list.RemoveAt(rand.Next(list.Count));
                    }

                    Verify(list);
                }
                Logger.LogMessage("Size {0}", list.Count);
            }
        }
Ejemplo n.º 2
0
        private static int VerifyCounts <T>(RedBlackList <T> .Node tree) where T : IComparable <T>
        {
            if (tree == null)
            {
                return(0);
            }

            Assert.IsTrue(tree.Count == VerifyCounts(tree.Left) + VerifyCounts(tree.Right) + 1, "Count Violation");
            return(tree.Count);
        }
Ejemplo n.º 3
0
        public void TestListIndex()
        {
            var rbList = new RedBlackList <int> {
                Enumerable.Range(0, 1000)
            };
            var list = new List <int>();

            list.AddRange(rbList);

            for (int i = 0; i < list.Count; i++)
            {
                Assert.IsTrue(list[i] == rbList[i]);
            }
        }
Ejemplo n.º 4
0
 public static void Verify <T>(RedBlackList <T> tree) where T : IComparable <T>
 {
     Verify((BaseRedBlackTree <RedBlackList <T> .Node>)tree);
     Assert.IsTrue(VerifyCounts(tree.Root) == tree.Count);
 }