コード例 #1
0
 public void QuickSort_NegativeNumbersTest()
 {
     int[] massive       = { -23, -48, -34, -9, -4 };
     int[] sortedMassive = { -48, -34, -23, -9, -4 };
     SortClass.QuickSort(massive);
     for (int i = 0; i < massive.Length; i++)
     {
         Assert.AreEqual(massive[i], sortedMassive[i]);
     }
 }
コード例 #2
0
 public void QuickSort_PositiveNumbersTest()
 {
     int[] massive       = { 5, 3, 7, 9, 1 };
     int[] sortedMassive = { 1, 3, 5, 7, 9 };
     SortClass.QuickSort(massive);
     for (int i = 0; i < massive.Length; i++)
     {
         Assert.AreEqual(massive[i], sortedMassive[i]);
     }
 }
コード例 #3
0
        public void QuickSort_Test1()
        {
            int[] array    = new int[] { 6, 4, 8, 2, 9, 1 };
            int[] expected = new int[] { 1, 2, 4, 6, 8, 9 };

            SortClass sortClass = new SortClass();

            array = sortClass.QuickSort(array);

            CollectionAssert.AreEqual(expected, array);
        }
コード例 #4
0
        public void QuickSort_Test4()
        {
            int[] array    = new int[0];
            int[] expected = new int[0];

            SortClass sortClass = new SortClass();

            array = sortClass.QuickSort(array);

            CollectionAssert.AreEqual(expected, array);
        }
コード例 #5
0
        public void QuickSort_Test3()
        {
            int[] array    = new int[] { 5, 4, 3, 2, 1 };
            int[] expected = new int[] { 1, 2, 3, 4, 5 };

            SortClass sortClass = new SortClass();

            array = sortClass.QuickSort(array);

            CollectionAssert.AreEqual(expected, array);
        }
コード例 #6
0
 public void QuickSort_IntMaxAndMinValueAndZeroTest()
 {
     int[] massive       = { 0, int.MaxValue, int.MinValue };
     int[] sortedMassive = { int.MinValue, 0, int.MaxValue };
     SortClass.QuickSort(massive);
     for (int i = 0; i < massive.Length; i++)
     {
         Assert.AreEqual(massive[i], sortedMassive[i]);
         Assert.Equals(massive, sortedMassive);
     }
 }
コード例 #7
0
        public void test()
        {
            Stopwatch timePerParse;
            var       numbers       = 16;
            long      ticksThisTime = 0;

            int[] datata = new int[numbers];
            for (int i = 0; i < numbers; i++)
            {
                Random random = new Random();
                var    number = random.Next(0, 10000);
                datata[i] = number;
            }
            var data2 = new int[datata.Length];
            var data3 = new int[datata.Length];
            var data4 = new int[datata.Length];
            var data5 = new int[datata.Length];

            datata.CopyTo(data2, 0);
            datata.CopyTo(data3, 0);
            datata.CopyTo(data4, 0);
            datata.CopyTo(data5, 0);

            timePerParse = Stopwatch.StartNew();
            SortClass.Sort(ref datata);
            timePerParse.Stop();
            ticksThisTime = timePerParse.ElapsedTicks;
            Console.WriteLine("MainSort     " + ticksThisTime);


            timePerParse = Stopwatch.StartNew();
            SortClass.QuickSort(ref data2, data2[0], data2.Length - 1);
            timePerParse.Stop();
            ticksThisTime = timePerParse.ElapsedTicks;
            Console.WriteLine("QuickSort     " + ticksThisTime);


            timePerParse = Stopwatch.StartNew();
            SortClass.InsertionSort(ref data4);
            timePerParse.Stop();
            ticksThisTime = timePerParse.ElapsedTicks;
            Console.WriteLine("InsertionSort     " + ticksThisTime);

            timePerParse = Stopwatch.StartNew();
            SortClass.HeapSort(ref data5);
            timePerParse.Stop();
            ticksThisTime = timePerParse.ElapsedTicks;
            Console.WriteLine("HeapSort      " + ticksThisTime);
        }
コード例 #8
0
 public void QuickSort_NullArray()
 {
     SortClass.QuickSort(null);
 }