public void TestQuickSortTailOptimization_11()
        {
            int[] array = new int[] { 5, 4 };
            int[] expay = new int[] { 4, 5 };
            SortLevel.QuickSortTailOptimization(array, 0, 1);

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

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

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

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
        public void TestQuickSortTailOptimization_8()
        {
            int[] array = InstantiateArray_1();
            int[] expay = InstantiateArray_2();

            SortLevel.QuickSortTailOptimization(array, 0, 4999);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
        public void TestQuickSortTailOptimization_7()
        {
            int[] array = new int[500];
            int[] expay = new int[500];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = 1500 - i;
                expay[i] = 1001 + i;
            }
            SortLevel.QuickSortTailOptimization(array, 0, 499);

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

            int[] expectedArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            SortLevel.QuickSortTailOptimization(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]);
            }
        }
Esempio n. 8
0
        public static void TestQuickSortTailOptimization()
        {
            var array = new int[] { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };

            SortLevel.QuickSortTailOptimization(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.QuickSortTailOptimization(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]);
            }
        }