コード例 #1
0
        public static void TestMergeSort()
        {
            var array = new List <int> {
                3, 5, 2, 4, 1
            };
            var        result  = SortLevel.MergeSort(array);
            List <int> ethalon = new List <int> {
                1, 2, 3, 4, 5
            };

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

            var array2 = new List <int> {
                10, 14, 3, 12, 11, 1, 9, 15, 7, 6, 5, 4, 13, 2, 8
            };
            var result2  = SortLevel.MergeSort(array2);
            var ethalon2 = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
            };

            Assert.AreEqual(ethalon2.Count, result2.Count);
            for (int i = 0; i < result2.Count; i++)
            {
                Assert.AreEqual(ethalon2[i], result2[i]);
            }
        }
コード例 #2
0
        public void TestMergeSort_1()
        {
            List <int> list = new List <int>()
            {
                4, 5, 6, 7, 1, 2, 3
            };

            int[] expay = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            list = SortLevel.MergeSort(list);
            int c = 0;

            foreach (int i in list)
            {
                Assert.AreEqual(expay[c++], i);
            }
        }
コード例 #3
0
        public void TestMergeSort_10()
        {
            List <int> list = new List <int>()
            {
                4, 3, 5, 2, 1
            };

            int[] expay = new int[] { 1, 2, 3, 4, 5 };
            list = SortLevel.MergeSort(list);
            int c = 0;

            foreach (int i in list)
            {
                Assert.AreEqual(expay[c++], i);
            }
            Assert.AreEqual(5, list.Count);
        }
コード例 #4
0
        public void TestMergeSort_9()
        {
            List <int> list = new List <int>()
            {
                6, 5, 8, 7, 2, 1, 4, 3
            };

            int[] expay = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            list = SortLevel.MergeSort(list);
            int c = 0;

            foreach (int i in list)
            {
                Assert.AreEqual(expay[c++], i);
            }
            Assert.AreEqual(8, list.Count);
        }
コード例 #5
0
        public void MergeSortTest_10()
        {
            List <int> array = new List <int> {
                9, 8, 7, 6, 5, 4, 3, 2, 1, 0
            };

            List <int> expectedList = new List <int> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            int expectedCount = 10;

            List <int> actualList = SortLevel.MergeSort(array);

            Assert.AreEqual(expectedCount, actualList.Count);

            Console.Write("\nИтоговый массив: ");
            actualList.ForEach(item => Console.Write(item + " "));

            for (int i = 0; i < actualList.Count; i++)
            {
                Assert.AreEqual(expectedList[i], actualList[i]);
            }
        }
コード例 #6
0
        public void MergeSortTest_5()
        {
            List <int> array = new List <int> {
                19, 13, 6, 7, 5
            };

            List <int> expectedList = new List <int> {
                5, 6, 7, 13, 19
            };
            int expectedCount = 5;

            List <int> actualList = SortLevel.MergeSort(array);

            Assert.AreEqual(expectedCount, actualList.Count);

            Console.Write("\nИтоговый массив: ");
            actualList.ForEach(item => Console.Write(item + " "));

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