Пример #1
0
        /// <exception cref="System.Exception"/>
        public virtual void SortAllEqual(IndexedSorter sorter)
        {
            int Sample = 500;

            int[] values = new int[Sample];
            Arrays.Fill(values, 10);
            TestIndexedSort.SampleSortable s = new TestIndexedSort.SampleSortable(values);
            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));
            // Set random min/max, re-sort.
            Random r   = new Random();
            int    min = r.Next(Sample);
            int    max = (min + 1 + r.Next(Sample - 2)) % Sample;

            values[min] = 9;
            values[max] = 11;
            System.Console.Out.WriteLine("testAllEqual setting min/max at " + min + "/" + max
                                         + "(" + sorter.GetType().FullName + ")");
            s = new TestIndexedSort.SampleSortable(values);
            sorter.Sort(s, 0, Sample);
            check = s.GetSorted();
            Arrays.Sort(values);
            Assert.True(check[0] == 9);
            Assert.True(check[Sample - 1] == 11);
            Assert.True(Arrays.ToString(values) + "\ndoesn't match\n" + Arrays
                        .ToString(check), 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 SortSequential(IndexedSorter sorter)
        {
            int Sample = 500;

            int[] values = new int[Sample];
            for (int i = 0; i < Sample; ++i)
            {
                values[i] = i;
            }
            TestIndexedSort.SampleSortable s = new TestIndexedSort.SampleSortable(values);
            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));
        }
Пример #4
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));
        }
Пример #5
0
        /// <exception cref="System.Exception"/>
        public virtual void SortSorted(IndexedSorter sorter)
        {
            int Sample = 500;

            int[]  values = new int[Sample];
            Random r      = new Random();
            long   seed   = r.NextLong();

            r.SetSeed(seed);
            System.Console.Out.WriteLine("testSorted seed: " + seed + "(" + sorter.GetType().
                                         FullName + ")");
            for (int i = 0; i < Sample; ++i)
            {
                values[i] = r.Next(100);
            }
            Arrays.Sort(values);
            TestIndexedSort.SampleSortable s = new TestIndexedSort.SampleSortable(values);
            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));
        }