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); }
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); }
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); }
public void MergeSort_PassesEmptyArray_ExpectsEmptyArray() { int[] actualResultArray = new int[0]; int[] expectResultArray = new int[0]; ArraySorter.MergeSort(actualResultArray); CollectionAssert.AreEqual(expectResultArray, actualResultArray); }
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); }
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); }
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); }
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)); }
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(); }
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)); } }
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)); } }
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)); } }
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); }
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); }
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]); } }
public void MergeSort_PassesUnsortedArray_ExpectsSortedArray() { // Arrange int n = 10000000; InitializeActualResultArrayAndExpectResultArray(n, int.MinValue, int.MaxValue); // Act ArraySorter.MergeSort(ActualResultArray); // Assert CollectionAssert.AreEqual(ExpectResultArray, ActualResultArray); }
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 }); }
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); } }
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 + " "); } }
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(); }
public void Init() { arraySorter = new ArraySorter(); }
public void BubbleSortTest_ArrayIsNull_ThrowsArgumentNullException(int[][] array) { var comparator = ComparatorFactory.GetAmountComparer(true); Assert.Throws <ArgumentNullException>(() => ArraySorter.BubbleSort(array, comparator)); }
public void MergeSort_ThrowException() { ArraySorter.QuickSort(null); }
public void MergeSort_PassesNullReference_ThrowArgumentNullExceptionn() => ArraySorter.MergeSort(null);
public void SortIntArray_WithNullArray_ThrowArgumentNullException() => Assert.Throws <ArgumentNullException>(() => ArraySorter.SortIntArray(null, "Quick"));
public void SortIntArray_WithEmptyArray_ThrowArgumentException() => Assert.Throws <ArgumentException>(() => ArraySorter.SortIntArray(Array.Empty <int>(), ""));
public void SortIntArray_WithNullString_ThrowArgumentNullException() => Assert.Throws <ArgumentNullException>(() => ArraySorter.SortIntArray(new int[3], null));
public void TearDown() { arraySorter = null; }
public void SortIntArray_WithWrongString_ThrowArgumentException() => Assert.Throws <ArgumentException>(() => ArraySorter.SortIntArray(new int[1], "wrong"));
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 }