public void KthOrderStatisticsStepTest()
        {
            int[] array = { 19, 13, 6, 7, 5 };

            int[]      expectedArray = { 5, 6, 7, 13, 19 };
            List <int> expectedList  = new List <int> {
                0, 1
            };

            List <int> actualList = SortLevel.KthOrderStatisticsStep(array, 0, array.Length - 1, 1);

            int[] actualArray = array;

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

            actualList.ForEach(item => Console.Write(item + " "));
            Console.WriteLine();

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

            for (int i = 0; i < actualList.Count; i++)
            {
                Assert.AreEqual(expectedList[i], actualList[i]);
            }
        }
Example #2
0
        public static void TestKthOrderStatisticsStep()
        {
            var        array   = new int[] { 3, 5, 2, 4, 1 };
            var        result  = SortLevel.KthOrderStatisticsStep(array, 0, 4, 0);
            List <int> ethalon = new List <int> {
                0, 3
            };

            Assert.AreEqual(ethalon.Count, result.Count);
            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(ethalon[i], result[i]);
            }
            result  = SortLevel.KthOrderStatisticsStep(array, 0, 3, 0);
            ethalon = new List <int> {
                0, 0
            };
            Assert.AreEqual(ethalon.Count, result.Count);
            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(ethalon[i], result[i]);
            }

            var        array2   = new int[] { 3, 5, 2, 4, 1 };
            var        result2  = SortLevel.KthOrderStatisticsStep(array2, 0, 4, 4);
            List <int> ethalon2 = new List <int> {
                4, 4
            };

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

            var        array1_teacher   = new int[] { 5, 6, 7, 4, 1, 2, 3 };
            var        result1_teacher  = SortLevel.KthOrderStatisticsStep(array1_teacher, 0, 6, 0);
            List <int> ethalon1_teacher = new List <int> {
                0, 2
            };

            Assert.AreEqual(ethalon1_teacher.Count, result1_teacher.Count);
            for (int i = 0; i < result1_teacher.Count; i++)
            {
                Assert.AreEqual(ethalon1_teacher[i], result1_teacher[i]);
            }
            var result2_teacher  = SortLevel.KthOrderStatisticsStep(array1_teacher, 0, 2, 0);
            var ethalon2_teacher = new List <int> {
                0, 0
            };

            Assert.AreEqual(ethalon2_teacher.Count, result2_teacher.Count);
            for (int i = 0; i < result2_teacher.Count; i++)
            {
                Assert.AreEqual(ethalon2_teacher[i], result2_teacher[i]);
            }
        }
        public void TestKthOrderStepTest_4()
        {
            int[]      array = new int[] { 4, 5, 6, 7, 1, 2, 3 };
            int[]      expay = new int[] { 1, 5, 4, 6, 7, 2, 3 };
            int[]      range = new int[] { 0, 0 };
            List <int> list  = SortLevel.KthOrderStatisticsStep(array, 0, 4, 0);

            int c = 0;

            foreach (int i in list)
            {
                Assert.AreEqual(range[c++], i);
            }
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
        public void TestKthOrderStepTest_3()
        {
            int[]      array = new int[] { 9, 8, 3, 4, 5, 1, 2 };
            int[]      expay = new int[] { 2, 1, 3, 4, 5, 8, 9 };
            int[]      range = new int[] { 4, 6 };
            List <int> list  = SortLevel.KthOrderStatisticsStep(array, 0, 6, 4);

            int c = 0;

            foreach (int i in list)
            {
                Assert.AreEqual(range[c++], i);
            }
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }