コード例 #1
0
 public void testReversedMergesortWithMeanValues()
 {
     double[] array = new double[] { 1.0, -0.0, -1.1, 2.0, 3.0, 0.0, 4.0, -0.0, 0.0 };
     shuffleArray(array);
     ArraySorter.reversedMergesort(array);
     assertDescendingOrder(array);
 }
コード例 #2
0
        public void TestMaxSort(double[,] arrUnSort, bool isDesc, int row, double[,] expected)
        {
            ArraySorter sorter = new ArraySorter();
            SortByMax   max    = new SortByMax();

            sorter.SelectMethod(max);
            Assert.AreEqual(sorter.Sort(isDesc, arrUnSort, row), expected);
        }
コード例 #3
0
        public void TestSumSort(double[,] arrUnSort, bool isDesc, int row, double[,] expected)
        {
            ArraySorter sorter = new ArraySorter();
            SortBySum   sum    = new SortBySum();

            sorter.SelectMethod(sum);
            Assert.AreEqual(sorter.Sort(isDesc, arrUnSort, row), expected);
        }
コード例 #4
0
        public void MergeSort_PassesEmptyArray_ExpectsEmptyArray()
        {
            int[] actualResultArray = new int[0];
            int[] expectResultArray = new int[0];

            ArraySorter.MergeSort(actualResultArray);

            CollectionAssert.AreEqual(expectResultArray, actualResultArray);
        }
コード例 #5
0
        public void SortIntArray_WithNormalArray_MergeSort()
        {
            int[] source = new int[] { 999, 101010, -1, 6, 6734, 5, 3, 90, 101 };
            int[] result = new int[] { -1, 3, 5, 6, 90, 101, 999, 6734, 101010 };

            ArraySorter.SortIntArray(source, "Merge");

            Assert.AreEqual(source, result);
        }
コード例 #6
0
        public void SortIntArray_WithSameElement_MergeSort()
        {
            int[] source = new int[] { 999, -999, -999, 999, -999, 999, -1, 1000 };
            int[] result = new int[] { -999, -999, -999, -1, 999, 999, 999, 1000 };

            ArraySorter.SortIntArray(source, "Merge");

            Assert.AreEqual(source, result);
        }
コード例 #7
0
        public void SortIntArray_WithMaxAndMinValue_QuickSort()
        {
            int[] source = new int[] { 1, 2, 85, int.MinValue, 1234, int.MaxValue, -10 };
            int[] result = new int[] { int.MinValue, -10, 1, 2, 85, 1234, int.MaxValue };

            ArraySorter.SortIntArray(source, "Quick");

            Assert.AreEqual(source, result);
        }
コード例 #8
0
        public void GivenArrayIsInitialized_WhenItContainsUnorderedIntElements_ThenItIsDescSorted(int[] given, int[] expected)
        {
            // Assert.
            var sut = new ArraySorter();
            // Act.
            var actual = sut.SortArrayDesc(given);

            // Assert.
            Assert.IsTrue(actual.SequenceEqual(expected));
        }
コード例 #9
0
        public AlgorithmTests()
        {
            sorter = new ArraySorter <int>();

            integers      = new[] { 9, 5, 1, 6, 2, 4, 3, 8, 7 };
            equalIntegers = new[] { 9, 5, 9, 8, 2, 9, 5, 8, 2 };

            sortedIntegers      = integers.OrderBy(x => x).ToArray();
            sortedEqualIntegers = equalIntegers.OrderBy(x => x).ToArray();
        }
コード例 #10
0
        public void DecreaseMaxItemBubbleSortTests()
        {
            for (int j = 0; j < CountRepeat; j++)
            {
                var array = SorterTestsHelper.GenerateArray(Guid.NewGuid().GetHashCode());

                ArraySorter.BubbleSort(array, ComparatorFactory.GetMaxItemComparer(false));

                Assert.IsTrue(SorterTestsHelper.IsTrustOrder(array, arr => arr.Max(), (a, b) => a < b));
            }
        }
コード例 #11
0
        public void DecreaseAmountBubbleSortIComparerTests()
        {
            for (int j = 0; j < CountRepeat; j++)
            {
                var array = SorterTestsHelper.GenerateArray(Guid.NewGuid().GetHashCode());

                ArraySorter.BubbleSort(array, ComparatorFactory.GetAmountComparisonDelegate(false));

                Assert.IsTrue(SorterTestsHelper.IsTrustOrder(array, arr => arr.Sum(), (a, b) => a < b));
            }
        }
コード例 #12
0
        public void IncreaseMinItemBubbleIComparerSortTests()
        {
            for (int j = 0; j < CountRepeat; j++)
            {
                var array = SorterTestsHelper.GenerateArray(Guid.NewGuid().GetHashCode());

                ArraySorter.BubbleSort(array, ComparatorFactory.GetMinItemComparisonDelegate(true));

                Assert.IsTrue(SorterTestsHelper.IsTrustOrder(array, arr => arr.Min(), (a, b) => a > b));
            }
        }
コード例 #13
0
        private void Sort(ISortingStrategy algorithm, long[] unsortedArray, out long[] manuallySorted, out long[] dotnetSorted)
        {
            manuallySorted = (long[])unsortedArray.Clone();
            dotnetSorted   = (long[])unsortedArray.Clone();

            ArraySorter sorter = new ArraySorter(algorithm);

            sorter.Sort(manuallySorted);

            Array.Sort(dotnetSorted);
        }
コード例 #14
0
        public void QuickSort_PassesUnsortedArrayOfNegativeValues_ExpectsSortedArray()
        {
            int n        = 100;
            int minValue = -100;
            int maxValue = 0;

            InitializeActualResultArrayAndExpectResultArray(n, minValue, maxValue);

            ArraySorter.QuickSort(ActualResultArray);

            CollectionAssert.AreEqual(ExpectResultArray, ActualResultArray);
        }
コード例 #15
0
        public void MergeSort_NormalSort()
        {
            int[] array  = { 5, 2, 1, 4, 3 };
            int[] result = { 1, 2, 3, 4, 5 };

            ArraySorter.MergeSort(array);

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(result[i], array[i]);
            }
        }
コード例 #16
0
        public void MergeSort_PassesUnsortedArray_ExpectsSortedArray()
        {
            // Arrange
            int n = 10000000;

            InitializeActualResultArrayAndExpectResultArray(n, int.MinValue, int.MaxValue);

            // Act
            ArraySorter.MergeSort(ActualResultArray);

            // Assert
            CollectionAssert.AreEqual(ExpectResultArray, ActualResultArray);
        }
コード例 #17
0
        public async Task <SavedData> Create(SortingInput input)
        {
            long[] array = input.GetNumbers();

            ArraySorter sorter = new ArraySorter(new MergeSort());

            sorter.Sort(array);

            string orderedNumbers = StringHelper.Concat(array);

            string fileName = await _fileService.SaveToFile(orderedNumbers);

            return(new SavedData {
                OrderedNumbers = orderedNumbers, FileName = fileName
            });
        }
コード例 #18
0
        public void testReversedMergesort()
        {
            for (int k = 1; k <= 16 * 8096; k *= 2)
            {
                // create random array
                double[] array = new double[k];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = random.NextDouble();
                }


                ArraySorter.reversedMergesort(array);
                assertDescendingOrder(array);
            }
        }
コード例 #19
0
        static void Main()
        {
            int[] arr = { 3, 0, 1, 8, 7, 2, 5, 4, 9, 6 };
            ArraySorter.QuickSort(arr);

            foreach (var num in arr)
            {
                Console.Write(num + " ");
            }

            Console.WriteLine();

            arr = new [] { 3, 0, 1, 8, 7, 2, 5, 4, 9, 6 };
            ArraySorter.MergeSort(arr);

            foreach (var num in arr)
            {
                Console.Write(num + " ");
            }
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: emilieDelsol/CSHARP-WCS
        static void Main(string[] args)
        {
            /*Console.WriteLine("Entrer une taille de Tableau :");
             * int sizeTable = Convert.ToInt32(Console.ReadLine());
             * for (int i = 0; i < sizeTable; i++)
             *  Console.WriteLine("Entrer un nombre :");
             *  int number = Convert.ToInt32(Console.ReadLine());
             * {
             *  int arr[i] = number;
             * }*/
            int[] integer = new int[10] {
                23, 9, 85, 12, 99, 34, 60, 15, 100, 1
            };

            ArraySorter arraySorter = new ArraySorter();



            arraySorter.Ecriture(integer);
            Console.WriteLine("First table: ");
            arraySorter.Lecture();
            Console.WriteLine("Insertion Sort :");
            arraySorter.InsertionSort(integer);
            arraySorter.Lecture();

            int[] integer2 = new int[5] {
                78, 55, 45, 98, 13
            };

            arraySorter.Ecriture(integer2);
            Console.WriteLine("Second table: ");
            arraySorter.Lecture();
            Console.WriteLine("Bubble Sort :");
            arraySorter.BubbleSort(integer2);
            arraySorter.Lecture();
        }
コード例 #21
0
 public void Init()
 {
     arraySorter = new ArraySorter();
 }
コード例 #22
0
        public void BubbleSortTest_ArrayIsNull_ThrowsArgumentNullException(int[][] array)
        {
            var comparator = ComparatorFactory.GetAmountComparer(true);

            Assert.Throws <ArgumentNullException>(() => ArraySorter.BubbleSort(array, comparator));
        }
コード例 #23
0
 public void MergeSort_ThrowException()
 {
     ArraySorter.QuickSort(null);
 }
コード例 #24
0
 public void MergeSort_PassesNullReference_ThrowArgumentNullExceptionn() => ArraySorter.MergeSort(null);
コード例 #25
0
 public void SortIntArray_WithNullArray_ThrowArgumentNullException()
 => Assert.Throws <ArgumentNullException>(() => ArraySorter.SortIntArray(null, "Quick"));
コード例 #26
0
 public void SortIntArray_WithEmptyArray_ThrowArgumentException()
 => Assert.Throws <ArgumentException>(() => ArraySorter.SortIntArray(Array.Empty <int>(), ""));
コード例 #27
0
 public void SortIntArray_WithNullString_ThrowArgumentNullException()
 => Assert.Throws <ArgumentNullException>(() => ArraySorter.SortIntArray(new int[3], null));
コード例 #28
0
 public void TearDown()
 {
     arraySorter = null;
 }
コード例 #29
0
 public void SortIntArray_WithWrongString_ThrowArgumentException()
 => Assert.Throws <ArgumentException>(() => ArraySorter.SortIntArray(new int[1], "wrong"));
コード例 #30
0
ファイル: Program.cs プロジェクト: AdamSai/SortingShakespeare
        static void Main(string[] args)
        {
            var textProcessor = new TextProcessor();
            var regexPattern  = @"[a-zA-ZæøåÆØÅ]+'?-?[a-zA-ZæøåÆØÅ]*";

            textProcessor.ProcessTextFile(@"..\..\..\shakespeare-complete-works.txt", regexPattern);
            var dataLength = textProcessor.ProcessedStrings.Length;

            var stopwatch = Stopwatch.StartNew();


            #region Selection Sort

            // Take the first 10.000 elements from the original array
            var sampleData = textProcessor.ProcessedStrings.Take(10000).ToArray();
            Selection.Sort(sampleData);
            stopwatch.Stop();
            PrintElapsedTime(sampleData.Length, stopwatch.ElapsedMilliseconds, "Selection Sort");

            #endregion

            #region Insertion sort

            sampleData = textProcessor.ProcessedStrings.Take(10000).ToArray();
            stopwatch  = Stopwatch.StartNew();
            Insertion.Sort(sampleData);
            stopwatch.Stop();
            PrintElapsedTime(sampleData.Length, stopwatch.ElapsedMilliseconds, "Insertion Sort");

            #endregion

            #region Merge Sort

            stopwatch = Stopwatch.StartNew();
            Merge.Sort(textProcessor.ProcessedStrings);
            stopwatch.Stop();
            PrintElapsedTime(dataLength, stopwatch.ElapsedMilliseconds, "Merge Sort");

            #endregion

            #region Heap Sort

            // Read the file again so the array is back in it's original state
            textProcessor.ProcessTextFile(@"..\..\..\shakespeare-complete-works.txt", regexPattern);
            stopwatch = Stopwatch.StartNew();
            ArraySorter <string> .SortAscending(textProcessor.ProcessedStrings);

            stopwatch.Stop();
            PrintElapsedTime(dataLength, stopwatch.ElapsedMilliseconds, "Heap Sort");

            #endregion

            #region Trie Sort

            textProcessor.ProcessTextFile(@"..\..\..\shakespeare-complete-works.txt", regexPattern);
            stopwatch = Stopwatch.StartNew();
            Trie.Sort(textProcessor.ProcessedStrings);
            stopwatch.Stop();
            PrintElapsedTime(dataLength, stopwatch.ElapsedMilliseconds, "Trie");

            #endregion
        }