示例#1
0
        public void SelectionSortStepTest()
        {
            int[] arr  = new int[] { 4, 3, 1, 2 };
            var   arr1 = new int[] { 4, 3, 1, 2 };
            var   arr2 = new int[] { 4, 3, 1, 2 };
            var   arr3 = new int[] { 4, 3, 1, 2 };
            var   opt0 = SortLevel.SelectionSortStep(arr, 0);

            Thread.Sleep(100);
            var opt1 = SortLevel.SelectionSortStep(arr1, 1);

            Thread.Sleep(100);
            var opt2 = SortLevel.SelectionSortStep(arr2, 2);

            Thread.Sleep(100);
            var opt3 = SortLevel.SelectionSortStep(arr3, 3);

            Thread.Sleep(100);
            if (!(opt0[0] == 1 && opt0[1] == 3 && opt0[2] == 4 && opt0[3] == 2))
            {
                Assert.Fail();
            }
            if (!(opt1[0] == 4 && opt1[1] == 1 && opt1[2] == 3 && opt1[3] == 2))
            {
                Assert.Fail();
            }
            if (!(opt2[0] == 4 && opt2[1] == 3 && opt2[2] == 1 && opt2[3] == 2))
            {
                Assert.Fail();
            }
            if (!(opt3[0] == 4 && opt3[1] == 3 && opt3[2] == 1 && opt3[3] == 2))
            {
                Assert.Fail();
            }
        }
        public void SelectionSortStep_if_Array_is_Empty()
        {
            int[] testArr = { };

            SortLevel.SelectionSortStep(testArr, 0);

            Assert.IsNotNull(testArr);
            Assert.IsTrue(testArr.Length == 0);
        }
        public void TestSelection_1()
        {
            int[] array = new int[] { 7, 42, 25 };
            SortLevel.SelectionSortStep(array, 1);

            Assert.AreEqual(7, array[0]);
            Assert.AreEqual(25, array[1]);
            Assert.AreEqual(42, array[2]);
            Assert.AreEqual(3, array.Length);
        }
        public void TestSelection_5()
        {
            int[] array = new int[] { 1, 4, 5, 2, 3 };
            int[] expay = new int[] { 1, 2, 5, 4, 3 };
            SortLevel.SelectionSortStep(array, 1);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
        public void TestSelection_2()
        {
            int[] array = new int[] { 7, 42, 25, 82, 5, 20 };
            int[] expay = new int[] { 7, 5, 25, 82, 42, 20 };
            SortLevel.SelectionSortStep(array, 1);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
示例#6
0
        public static void TestSelectionSortStep()
        {
            SortLevel.SelectionSortStep(_array, 0);
            var ethalon = new int[] { 1, 3, 4, 2 };

            Assert.AreEqual(ethalon.Length, _array.Length);
            for (int i = 0; i < _array.Length; i++)
            {
                Assert.AreEqual(ethalon[i], _array[i]);
            }
        }
        public void SelectionSortStep_if_Array_Has_1_Elem()
        {
            int[] testArr = { 19 };

            SortLevel.SelectionSortStep(testArr, 0);

            int expected = 19;

            Assert.IsNotNull(testArr);
            Assert.IsTrue(testArr.Length == 1);

            Assert.AreEqual(expected, testArr[0]);
        }
        public void SelectionSortStep_if_Array_Has_2_Elem()
        {
            int[] testArr = { 21, 19 };

            SortLevel.SelectionSortStep(testArr, 0);

            Assert.IsNotNull(testArr);
            Assert.IsTrue(testArr.Length == 2);

            int[] expectedSortedArr = new int[] { 19, 21 };

            for (int i = 0; i < testArr.Length; i++)
            {
                Assert.AreEqual(expectedSortedArr[i], testArr[i]);
            }
        }
        public void SelectionSortStepTest()
        {
            int[] testArr = { 4, 3, 1, 2 };
            Array.ForEach(testArr, (item) => Console.Write(item + " "));
            Console.WriteLine();

            SortLevel.SelectionSortStep(testArr, 0);
            foreach (int item in testArr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            int[] expectedSortedArr = new int[] { 1, 3, 4, 2 };

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