Пример #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestQuickSort()
        {
            QuickSort sorter = new QuickSort();

            SortRandom(sorter);
            SortSingleRecord(sorter);
            SortSequential(sorter);
            SortSorted(sorter);
            SortAllEqual(sorter);
            SortWritable(sorter);
            // test degenerate case for median-of-three partitioning
            // a_n, a_1, a_2, ..., a_{n-1}
            int Dsample = 500;

            int[] values = new int[Dsample];
            for (int i = 0; i < Dsample; ++i)
            {
                values[i] = i;
            }
            values[0] = values[Dsample - 1] + 1;
            TestIndexedSort.SampleSortable s = new TestIndexedSort.SampleSortable(values);
            values = s.GetValues();
            int Dss = (Dsample / 2) * (Dsample / 2);

            // Worst case is (N/2)^2 comparisons, not including those effecting
            // the median-of-three partitioning; impl should handle this case
            TestIndexedSort.MeasuredSortable m = new TestIndexedSort.MeasuredSortable(s, Dss);
            sorter.Sort(m, 0, Dsample);
            System.Console.Out.WriteLine("QuickSort degen cmp/swp: " + m.GetCmp() + "/" + m.GetSwp
                                             () + "(" + sorter.GetType().FullName + ")");
            Arrays.Sort(values);
            int[] check = s.GetSorted();
            Assert.True(Arrays.Equals(values, check));
        }
Пример #2
0
        /// <exception cref="System.Exception"/>
        public virtual void SortSingleRecord(IndexedSorter sorter)
        {
            int Sample = 1;

            TestIndexedSort.SampleSortable s = new TestIndexedSort.SampleSortable(Sample);
            int[] values = s.GetValues();
            sorter.Sort(s, 0, Sample);
            int[] check = s.GetSorted();
            Assert.True(Arrays.ToString(values) + "\ndoesn't match\n" + Arrays
                        .ToString(check), Arrays.Equals(values, check));
        }
Пример #3
0
        /// <exception cref="System.Exception"/>
        public virtual void SortRandom(IndexedSorter sorter)
        {
            int Sample = 256 * 1024;

            TestIndexedSort.SampleSortable s = new TestIndexedSort.SampleSortable(Sample);
            long seed = s.GetSeed();

            System.Console.Out.WriteLine("sortRandom seed: " + seed + "(" + sorter.GetType().
                                         FullName + ")");
            int[] values = s.GetValues();
            Arrays.Sort(values);
            sorter.Sort(s, 0, Sample);
            int[] check = s.GetSorted();
            Assert.True("seed: " + seed + "\ndoesn't match\n", Arrays.Equals
                            (values, check));
        }