Example #1
0
 public static void InOrder(TreeSet tree)
 {
     object last = null;
     foreach (object o in tree)
     {
         if (last != null)
             Debug.Assert(((IComparable)last).CompareTo(o) < 0, "Out of order");
     }
 }
Example #2
0
        /// <summary>
        /// Brute-force correctness test of insert/delete operations.
        /// </summary>
        public static void Test()
        {
            TreeSet ts = new TreeSet();
            int count = 0;

            for (int loops = 0; ; loops++)
            {
                count += ts.AddAll(RandomArrayList(100000 - ts.Count));

                InOrder(ts);

                ArrayList data = ts.ToArrayList();

                RandomizeOrder(ref data);

                for (int i = 0; i < 50000 && i < data.Count; i++)
                {
                    if (ts.Remove(data[i]))
                        count--;
                }

                Debug.Assert(count == ts.Count);
                InOrder(ts);

                if ((loops % 10) == 0)
                Console.WriteLine("So far so good: " + loops + " " + count);
            }
        }