Exemplo n.º 1
0
        public static void Benchmarks()
        {
            AssumeTrue("Turn VERBOSE on or otherwise you won't see the results.", Verbose);

            int maxSize             = AtLeast(100000);
            PriorityQueue <int?> pq = new IntegerQueue(maxSize);

            int?[] elements = new int?[maxSize];

            for (int i = 0; i < maxSize; i++)
            {
                elements[i] = Random.Next();
            }

            Console.WriteLine("Random list of elements...");

            TimedAddAndPop <int?>(pq, elements);
            pq.Clear();

            Console.WriteLine("\nSorted list of elements...");

            pq = new IntegerQueue(maxSize);
            ArrayUtil.IntroSort(elements, new Less());
            TimedAddAndPop <int?>(pq, elements);
            pq.Clear();

            Console.WriteLine("\nReverse sorted list of elements...");

            pq = new IntegerQueue(maxSize);
            ArrayUtil.IntroSort(elements, new Greater());
            TimedAddAndPop <int?>(pq, elements);
            pq.Clear();
        }
Exemplo n.º 2
0
 public virtual void TestEmptyArraySort()
 {
     int[] a = new int[0];
     ArrayUtil.IntroSort(a);
     ArrayUtil.TimSort(a);
     ArrayUtil.IntroSort(a, Collections.ReverseOrder <int>());
     ArrayUtil.TimSort(a, Collections.ReverseOrder <int>());
 }
Exemplo n.º 3
0
 public virtual void TestEmptyArraySort()
 {
     int[] a = new int[0];
     ArrayUtil.IntroSort(a);
     ArrayUtil.TimSort(a);
     ArrayUtil.IntroSort(a, ReverseOrder);
     ArrayUtil.TimSort(a, ReverseOrder);
 }
Exemplo n.º 4
0
        public virtual void TestEmptyArraySort()
        {
#if FEATURE_ARRAYEMPTY
            int[] a = Array.Empty <int>();
#else
            int[] a = new int[0];
#endif
            ArrayUtil.IntroSort(a);
            ArrayUtil.TimSort(a);
            ArrayUtil.IntroSort(a, Collections.ReverseOrder <int>());
            ArrayUtil.TimSort(a, Collections.ReverseOrder <int>());
        }
Exemplo n.º 5
0
        public virtual void TestQuickToHeapSortFallback()
        {
            int num = AtLeast(50);

            for (int i = 0; i < num; i++)
            {
                int[] a1 = CreateSparseRandomArray(40000);
                int[] a2 = (int[])a1.Clone();
                ArrayUtil.IntroSort(a1);
                Array.Sort(a2);
                Assert.AreEqual(a2, a1);
            }
        }
Exemplo n.º 6
0
        public static void TestPersistence()
        {
            // Tests that a big number of elements are added and popped (in the correct order)
            // without losing any information

            int maxSize             = AtLeast(100000);
            PriorityQueue <int?> pq = new IntegerQueue(maxSize);

            int?[] elements = new int?[maxSize];
            for (int i = 0; i < maxSize; i++)
            {
                elements[i] = Random.Next();
            }

            AddElements(pq, elements);

            ArrayUtil.IntroSort(elements, new Less());

            PopAndTestElements(pq, elements);
        }
Exemplo n.º 7
0
        public virtual void TestIntroSort()
        {
            int num = AtLeast(50);

            for (int i = 0; i < num; i++)
            {
                int[] a1 = CreateRandomArray(2000);
                int[] a2 = (int[])a1.Clone();
                ArrayUtil.IntroSort(a1);
                Array.Sort(a2);
                Assert.AreEqual(a2, a1);

                a1 = CreateRandomArray(2000);
                a2 = (int[])a1.Clone();
                ArrayUtil.IntroSort(a1, Collections.ReverseOrder <int>());
                Array.Sort(a2, Collections.ReverseOrder <int>());
                Assert.AreEqual(a2, a1);
                // reverse back, so we can test that completely backwards sorted array (worst case) is working:
                ArrayUtil.IntroSort(a1);
                Array.Sort(a2);
                Assert.AreEqual(a2, a1);
            }
        }