public void TestQuickSort_1()
        {
            int[] array = new int[] { 1, 3, 4, 6, 5, 2, 8 };
            int[] expay = new int[] { 1, 2, 3, 4, 5, 6, 8 };
            SortLevel.QuickSort(array, 0, 6);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
        public void TestQuickSort_3()
        {
            int[] array = new int[] { 4, 2, 7, 1, 8, 5 };
            int[] expay = new int[] { 4, 2, 7, 1, 5, 8 };
            SortLevel.QuickSort(array, 3, 5);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
        public void TestQuickSort_16()
        {
            int[] array = new int[] { 1 };
            int[] expay = new int[] { 1 };
            SortLevel.QuickSort(array, 0, 0);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
        public void TestQuickSort_11()
        {
            int[] array = new int[] { 3, 2, 1, 0 };
            int[] expay = new int[] { 0, 1, 2, 3 };
            SortLevel.QuickSort(array, 0, 3);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
        public void QuickSortTest_2()
        {
            int[] array = { 19, 13, 6, 7, 5 };

            int[] expectedArray = { 5, 6, 7, 13, 19 };

            SortLevel.QuickSort(array, 0, array.Length - 1);
            int[] actualArray = array;

            Array.ForEach(actualArray, (item) => Console.Write(item + " "));
            Console.WriteLine();

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expectedArray[i], array[i]);
            }
        }
        public void TestQuickSort_18()
        {
            int[] array = new int[5000];
            int[] expay = new int[5000];
            for (int i = 0; i < array.Length; i++)
            {
                if (i > 2500)
                {
                    array[i] = i;
                    expay[i] = i;
                }
                else
                {
                    array[i] = 2500 - i;
                    expay[i] = i;
                }
            }
            SortLevel.QuickSort(array, 0, 4999);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
Beispiel #7
0
        public static void TestQuickSort()
        {
            var array = new int[] { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };

            SortLevel.QuickSort(array, 0, 14);
            var ethalon = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

            Assert.AreEqual(ethalon.Length, array.Length);
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(ethalon[i], array[i]);
            }

            var array2 = new int[] { 10, 14, 3, 12, 11, 1, 9, 15, 7, 6, 5, 4, 13, 2, 8 };

            SortLevel.QuickSort(array2, 0, 14);
            var ethalon2 = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

            Assert.AreEqual(ethalon2.Length, array2.Length);
            for (int i = 0; i < array2.Length; i++)
            {
                Assert.AreEqual(ethalon2[i], array2[i]);
            }
        }