public void Sort_PassValidArray_ReturnSortedArray()
        {
            var insertSorting = new MergeSorting();
            var sortedArray   = insertSorting.Sort(_toSortArray, 0, _toSortArray.Length - 1);

            CollectionAssert.AreEqual(sortedArray, _referenceSortedArray);
        }
        public void Sort_PassEmptyArray_ReturnEmptyArray()
        {
            var insertSorting = new MergeSorting();
            var sortedArray   = insertSorting.Sort(_emptyArray, 0, _emptyArray.Length - 1);

            CollectionAssert.AreEqual(sortedArray, _emptyArray);
        }
        public void Sort_PassOneElementArray_ReturnOneElementArray()
        {
            var insertSorting = new MergeSorting();
            var sortedArray   = insertSorting.Sort(_oneElementArray, 0, _oneElementArray.Length - 1);

            CollectionAssert.AreEqual(sortedArray, _oneElementArray);
        }
        private static void SortingAlgorithms()
        {
            var inputArr = new int[5] {
                2, 3, 1, 5, 6
            };

            #region OrderBy Range Problem using MergeSort
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            SortingProblems sortingProblems = new SortingProblems();
            Console.WriteLine("Given: {0}", inputArr.ToString());

            int i = 1, j = 3;
            sortingProblems.SortSelectedRanges <int[]>(inputArr, i, j);
            Console.WriteLine("Sorted: {0} i:{1}, j:{2}", inputArr.ToString(), i, j);
            stopwatch.Stop();
            Console.WriteLine("RunTime " + stopwatch.ElapsedMilliseconds);
            #endregion
            #region Merge sorting
            MergeSorting ms = new MergeSorting();

            Console.WriteLine("Input Arrays:");
            inputArr.All(a => { Console.Write("{0} ", a); return(true); });
            Console.WriteLine();
            Console.WriteLine("Sorted Arrays:");
            foreach (var item in ms.Run <int[]>(inputArr))
            {
                Console.Write("{0} ", item);
            }
            #endregion
        }
Exemple #5
0
        public void TestSortTableInts()
        {
            int[] tab       = new int[] { 10, 5, 6, 4, 3 };
            int[] resultTab = MergeSorting <int> .Sort(tab);

            int[] expectedTab = new[] { 3, 4, 5, 6, 10 };

            Assert.IsTrue(Enumerable.SequenceEqual(resultTab, expectedTab));
        }
Exemple #6
0
        public void MergeSorting_Sort__SuccessResult()
        {
            ISorting testClass = new MergeSorting();

            int[] array = new int[] { 1, 0, 2, 9, 3, 8, 4, 7, 5, 6, 10 };
            testClass.Sort(array);

            array.Should().Equal(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        }
Exemple #7
0
 static void Print(List<int> l)
 {
     MergeSorting<int> sort = new MergeSorting<int>();
     Console.Write($"{l.Count * Math.Log(l.Count):#0}: ");
     l.ForEach((x) => { Console.Write(x + " "); });
     Console.WriteLine();
     Console.Write(sort.Sort(l) + ": ");
     l.ForEach((x) => { Console.Write(x + " "); });
     Console.WriteLine();
 }
Exemple #8
0
        public void MergeSorting_RecursiveTest()
        {
            MergeSorting sorting = new MergeSorting();

            int[] tmp_array = new[] { 3, 2, 7, 3, 1, 6 };
            sorting.N = tmp_array.Length;

            sorting.MergeSort_Recursive(tmp_array, 1, 4);

            CollectionAssert.AreEqual(tmp_array, new int[] { 3, 1, 2, 3, 7, 6 });
        }
Exemple #9
0
        public void MergeSorting_DoMergeTest()
        {
            MergeSorting sorting = new MergeSorting();

            int[] tmp_array = new[] { 3, 2, 7, 3, 1, 6 };
            sorting.N = tmp_array.Length;

            sorting.DoMerge(tmp_array, 1, 3, 5);

            CollectionAssert.AreEqual(tmp_array, new int[] { 3, 2, 3, 1, 6, 7 });
        }
Exemple #10
0
        public void MergeSorting_SortTest()
        {
            MergeSorting sorting = new MergeSorting();

            sorting.Array = new[] { 3, 2, 7, 3, 1 };
            sorting.N     = sorting.Array.Length;

            sorting.Sort();

            CollectionAssert.AreEqual(sorting.Array, new int[] { 1, 2, 3, 3, 7 });
        }
Exemple #11
0
        public void MergeTwoCollections_But_LeftCollectionIsEmpty()
        {
            // Arrange && Act
            var result = new MergeSorting().Merge(new List <int> {
            }, new List <int> {
                20, 21
            });

            // Assert
            Assert.Equal(new List <int> {
                20, 21
            }, result);
        }
Exemple #12
0
        public void MergeTwoCollections()
        {
            // Arrange && Act
            var result = new MergeSorting().Merge(new List <int> {
                10, 11
            }, new List <int> {
                20, 21
            });

            // Assert
            Assert.Equal(new List <int> {
                10, 11, 20, 21
            }, result);
        }
Exemple #13
0
        public void MergeSorting_Test()
        {
            var rand = new Random();

            var list = Enumerable
                       .Range(1, 10000)
                       .Select(x => rand.Next())
                       .ToList();

            var actual = MergeSorting.Sort(list);

            list.Sort();

            Assert.Equal(list, actual);
        }
Exemple #14
0
        public void TestSortTableProduct()
        {
            Product[] productTable = new Product[] { new Product("jogurt", 0.2d, 3d),
                                                     new Product("margaryna", 0.5d, 3d),
                                                     new Product("masło", 0.5d, 5d),
                                                     new Product("kefir", 0.2d, 5d) };
            MergeSorting <Product> .Sort(productTable);

            Product[] productExpectedTable = new Product[] { new Product("margaryna", 0.5d, 3d),
                                                             new Product("masło", 0.5d, 5d),
                                                             new Product("jogurt", 0.2d, 3d),
                                                             new Product("kefir", 0.2d, 5d), };

            Assert.IsTrue(productExpectedTable.SequenceEqual(productTable));
        }
Exemple #15
0
        public void MergeSorting_FullTest()
        {
            MergeSorting sorting = new MergeSorting();

            sorting.SetGenerateStrategy(new DescSortedGenerateStrategy());

            sorting.TestSortingAlgorithm();

            int[] expected = new int [sorting.N];
            for (int i = 0; i < sorting.N; i++)
            {
                expected[i] = i + 1;
            }

            CollectionAssert.AreEqual(sorting.Array, expected);
        }
Exemple #16
0
        public void Test()
        {
            // Arrange
            var numbers = new List <int> {
                4, 3, 2, 1
            };
            var expected = new List <int> {
                1, 2, 3, 4
            };

            // Act
            var actual = new MergeSorting().Sort(numbers);

            // Assert
            Assert.Equal(expected, actual);
        }
Exemple #17
0
        public void DivideCollectionAndGetRightHalfTest()
        {
            // Arrange
            var numbers = new List <int> {
                1, 2, 3, 4
            };
            var expected = new List <int> {
                3, 4
            };
            var midway = numbers.Count / 2;

            // Act
            var rightHalf = new MergeSorting().DivideCollection(numbers, midway, numbers.Count);

            // Assert
            Assert.Equal(expected, rightHalf);
        }
 public void Test_Merge_Sort_When_Valid_Input1()
 {
     MergeSorting.Sort(new int[] { 4, 3, 2, 10, 12, 1, 5, 6 });
 }
Exemple #19
0
        public void MergeSorting_Sort()
        {
            ISorting testClass = new MergeSorting();

            testClass.Sort(SortedData);
        }