public static void Show() { int[] arr = new int[] { 10000, 20000, 30000, 40000, 50000, 100000, 200000, 500000, 1000000, 2000000, 5000000, 10000000, 100000000 }; foreach (int i in arr) { Console.WriteLine("Длина массива - " + i); int[] array = IntArrayGenerator.GenerateArray(i); Console.WriteLine("быстрая сортировка " + ", время выполнения - " + ActionTimeMeasurer.Measure(new Action(() => HoareSorter.Sort(array)))); array = IntArrayGenerator.GenerateArray(i); Console.WriteLine("встроенная сортировка " + ", время выполнения - " + ActionTimeMeasurer.Measure(new Action(() => Array.Sort(array)))); array = IntArrayGenerator.GenerateArray(i); Console.WriteLine("сортировка слиянием " + ", время выполнения - " + ActionTimeMeasurer.Measure(new Action(() => MergeSorter.Sort(array)))); GC.Collect(); Console.WriteLine(); } Console.ReadKey(); }
public void TestWithAnEmptyCollection() { List<int> collection = new List<int>(); MergeSorter<int> sorter = new MergeSorter<int>(); sorter.Sort(collection); Assert.AreEqual(0, collection.Count); }
public static void Show() { int[] arr = new int[] { 100, 500, 1000, 2000, 5000 }; foreach (int i in arr) { Console.WriteLine("Длина массива - " + i); string[] array = TextGenerator.GenerateText(i).Split(); Console.WriteLine("сортировка пузырьком O(n^2) " + ", время выполнения - " + ActionTimeMeasurer.Measure(new Action(() => BubbleSorter.Sort(array)))); array = TextGenerator.GenerateText(i).Split(); Console.WriteLine("сортировка вставками O(log(n)) " + ", время выполнения - " + ActionTimeMeasurer.Measure(new Action(() => MergeSorter.Sort(array)))); GC.Collect(); Console.WriteLine(); } Console.ReadKey(); }
public void TestEmptyList() { var sorter = new MergeSorter(); var list = new List<int> { }; sorter.Sort(list); Assert.AreEqual(0, list.Count); }
public void MergeSortZeroTest() { IList <int> arr = new List <int>(); MergeSorter <int> sorter = new MergeSorter <int>(); sorter.Sort(arr); }
public void ThrowInvalidOperationException_WhenCollectionIsEmpty() { var collection = new List <int>(); var sorter = new MergeSorter <int>(); Assert.Throws <InvalidOperationException>(() => sorter.Sort(collection)); }
public void When_sorting(int[] input, int[] answer) { var sorter = new MergeSorter <int>(); var sorted = sorter.Sort(input); Assert.Equal(sorted, answer); }
public void MergeSortNullTest() { IList <int> arr = null; MergeSorter <int> sorter = new MergeSorter <int>(); sorter.Sort(arr); }
public void Sort_NullArray_ReturnArgumentException() { int[] array = null; var sorter = new MergeSorter <int>(); sorter.Sort(array); }
public void PassingOneItemCollection() { List<int> numbers = new List<int>() {1}; MergeSorter<int> sorter = new MergeSorter<int>(numbers); List<int> sortedList = new List<int>(sorter.Sort()); Assert.AreEqual(numbers[0], sortedList[0]); }
static void Main(string[] args) { int[] a = ArrayUtil.RandomIntArray(20, 100); Console.WriteLine(ArrayUtil.ToString(a)); MergeSorter.Sort(a); Console.WriteLine(ArrayUtil.ToString(a)); }
public void TestProperList() { var sorter = new MergeSorter(); var list = new List<int> { 3, 2, 1, 9, 7 }; sorter.Sort(list); Assert.AreEqual(5, list.Count); Assert.IsTrue(list.SequenceEqual(new List<int> { 1, 2, 3, 7, 9 })); }
public void NaiveMergeSorter_SortStringsDescending_SortsCorrectly(IList <string> actual) { var sorter = new MergeSorter <string>(); sorter.Sort(actual, SortOrder.Descending); SortAssert.IsSortedDescending(actual, Comparer <string> .Default); }
public static void Main() { List<int> numbers = new List<int>() { 1,3,4,5,1,4,6,7,3,3,6,8,9,2 }; MergeSorter<int> mergeSorter = new MergeSorter<int>(numbers); numbers = mergeSorter.Sort(); Console.WriteLine(string.Join(",", numbers)); }
public void Sort_hugeArrayTest() { int[] unsortedArray_1 = GenerateArray(); int[] unsortedArray_2 = new int[1000]; unsortedArray_1.CopyTo(unsortedArray_2, 0); Array.Sort(unsortedArray_1); MergeSorter.Sort(unsortedArray_2); CollectionAssert.AreEqual(unsortedArray_1, unsortedArray_2); }
public void SortEmptyTest() { List <int> testCollection = new List <int>(); MergeSorter <int> testMergeSorter = new MergeSorter <int>(); testMergeSorter.Sort(testCollection); Assert.AreEqual(testCollection.Count, 0); }
public void Sort_EmptyArray_Success() { var sorter = new MergeSorter <int>(); var array = new int[0]; sorter.Sort(array); Assert.IsTrue(sorter.Ensure(array)); }
public void Sort_Should_Sort_Input(string input, string sortedInput) { var value = input; var expectedValue = sortedInput; var sorter = new MergeSorter(); var result = sorter.Sort(value); Assert.AreEqual(expectedValue, result); }
private static IList <T> UncheckedMergeSort <T>( this IList <T> list, int index, int count, Comparison <T> compare) { if (count == 0) { return(list); } MergeSorter.Sort(list.ToList(), list, index, index + count, compare); return(list); }
public void PassingSortedItemCollection() { List<int> sortedNumbers = new List<int>() { 1, 1, 2, 2, 2, 3, 4, 5, 5, 7, 8, 9 }; MergeSorter<int> sorter = new MergeSorter<int>(sortedNumbers); List<int> sortedList = new List<int>(sorter.Sort()); for (int i = 0; i < sortedNumbers.Count; i++) { Assert.AreEqual(sortedNumbers[i], sortedList[i]); } }
public void Sort_SingleElementArray_Success() { var sorter = new MergeSorter <int>(); var array = new int[1] { 0 }; sorter.Sort(array); Assert.IsTrue(sorter.Ensure(array)); }
public void Sort_ValidArray_Success() { var sorter = new MergeSorter <int>(); var array = new int[10] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; sorter.Sort(array); Assert.IsTrue(sorter.Ensure(array)); }
public void TestWithASingleItem() { List<int> collection = new List<int>(); collection.Add(3); MergeSorter<int> sorter = new MergeSorter<int>(); sorter.Sort(collection); Assert.AreEqual(1, collection.Count); Assert.AreEqual(3, collection[0]); }
public void MergeSortTest() { ISorter sorter = new MergeSorter(); sorter.Sort(data); for (int i = 0; i < result.Count; i++) { Assert.IsTrue(result[i] == data[i]); } }
public void SimpleMergeSortTest() { List<int> arrayToSort = new List<int>() { 2, 5, 3, 1, 4 }; MergeSorter<int> mergeSorter = new MergeSorter<int>(); List<int> expectedArray = new List<int>() { 1, 2, 3, 4, 5 }; mergeSorter.Sort(arrayToSort); CollectionAssert.AreEqual(expectedArray, arrayToSort); }
public void merge_sort_one_element_input_same_output() { int[] input = { 4 }; var sorter = new MergeSorter <int>(input); int[] actual = sorter.Sort(); int[] expected = { 4 }; actual.ShouldBeEquivalentTo(expected); }
public void merge_sort_two_elements_sorts_correctly() { int[] input = { 8, 4 }; var sorter = new MergeSorter <int>(input); int[] actual = sorter.Sort(); int[] expected = { 4, 8 }; actual.ShouldBeEquivalentTo(expected); }
public void merge_sort_empty_input_empty_output() { int[] input = { }; var sorter = new MergeSorter <int>(input); int[] actual = sorter.Sort(); int[] expected = { }; actual.ShouldBeEquivalentTo(expected); }
public void AlreadySortedNumsTest() { List<int> arrayToSort = new List<int>() { 1, 2, 3, 4, 5 }; MergeSorter<int> mergeSorter = new MergeSorter<int>(); List<int> expectedArray = new List<int>() { 1, 2, 3, 4, 5 }; mergeSorter.Sort(arrayToSort); CollectionAssert.AreEqual(expectedArray, arrayToSort); }
public void NaiveMergeSorter_EmptyList_RemainsEmptyList() { var expected = new List <string>(); var sorter = new MergeSorter <string>(); var actual = new List <string>(); sorter.Sort(actual); Assert.AreEqual(expected, actual); }
public void merge_sort_generic_two_elements_sorted_same_output() { string[] input = { "fa", "la" }; var sorter = new MergeSorter <string>(input); string[] actual = sorter.Sort(); string[] expected = { "fa", "la" }; actual.ShouldBeEquivalentTo(expected); }
public void merge_sort_generic_three_element_list() { string[] input = { "ba", "fa", "la" }; var sorter = new MergeSorter <string>(input); string[] actual = sorter.Sort(); string[] expected = { "ba", "fa", "la" }; actual.ShouldBeEquivalentTo(expected); }
public void merge_sort_generic_ten_element_list() { string[] input = { "do", "re", "mi", "fa", "so", "la", "ti", "do", "boo", "yah" }; var sorter = new MergeSorter <string>(input); string[] actual = sorter.Sort(); string[] expected = { "do", "do", "fa", "la", "mi", "re", "so", "ti", "boo", "yah" }; actual.ShouldBeEquivalentTo(expected); }
public void merge_sort_ten_element_list() { int[] input = { 9, 8, 7, 6, 5, 5, 4, 3, 2, 1 }; var sorter = new MergeSorter <int>(input); int[] actual = sorter.Sort(); int[] expected = { 1, 2, 3, 4, 5, 5, 6, 7, 8, 9 }; actual.ShouldBeEquivalentTo(expected); }
public void ShouldSortCharactersCorrectly() { var array = new char[] { 'a', 'c', 'b', 'z', 'a' }; var mergeSorter = new MergeSorter <char>(); mergeSorter.Sort(array); var expected = new char[] { 'a', 'a', 'b', 'c', 'z' }; CollectionAssert.AreEqual(expected, array); }
public void ShouldSortNegativeNumbersCorrectly() { var array = new int[] { -103, -166, -42, -3, -1 }; var mergeSorter = new MergeSorter <int>(); mergeSorter.Sort(array); var expected = new int[] { -166, -103, -42, -3, -1 }; CollectionAssert.AreEqual(expected, array); }
public void ShouldSortNumbersCorrectly() { var array = new int[] { 1, 4, 100, -3, 1 }; var mergeSorter = new MergeSorter <int>(); mergeSorter.Sort(array); var expected = new int[] { -3, 1, 1, 4, 100 }; CollectionAssert.AreEqual(expected, array); }
public void merge_sort_generic_empty_input_empty_output() { string[] input = { }; var sorter = new MergeSorter <string>(input); string[] actual = sorter.Sort(); string[] expected = { }; actual.ShouldBeEquivalentTo(expected); }
public void merge_sort_three_element_list() { int[] input = { 5, 6, 7 }; var sorter = new MergeSorter <int>(input); int[] actual = sorter.Sort(); int[] expected = { 5, 6, 7 }; actual.ShouldBeEquivalentTo(expected); }
public void ReversedNumberSortTest() { List<int> arrayToSort = new List<int>() { 5, 4, 3, 2, 1 }; MergeSorter<int> mergeSorter = new MergeSorter<int>(); List<int> expectedArray = new List<int>() { 1, 2, 3, 4, 5 }; mergeSorter.Sort(arrayToSort); CollectionAssert.AreEqual(expectedArray, arrayToSort); }
public void TestSortLengthOfCollection() { List<int> collection = new List<int>() { 3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23 }; int count = collection.Count; MergeSorter<int> sorter = new MergeSorter<int>(); sorter.Sort(collection); Assert.AreEqual(count, collection.Count); }
static void Main(string[] args) { double[] a = new double[100000]; for(int i=0; i<100000; i++) { a[i] = Math.Cos(i); } MergeSorter<double> ms = new MergeSorter<double>(); a = ms.Sort(a); Console.WriteLine("Done!"); }
/// <summary> /// エントリーポイント /// </summary> /// <param name="args"></param> static void Main(string[] args) { // データ準備 int[] array = { 9, 7, 8, 5, 6, 3, 4, 1, 2, 0 }; DebugPrint(array.ToList()); Debug.WriteLine("--------"); // バブルソート生成 var sorter = new MergeSorter(); sorter.OnUpdate += (sender, e) => DebugPrint(array.ToList()); // ソート実行 sorter.Sort(array); }
public void TestWithTwoItems() { List<int> collection = new List<int>(); collection.Add(3); collection.Add(0); MergeSorter<int> sorter = new MergeSorter<int>(); sorter.Sort(collection); Assert.AreEqual(2, collection.Count); Assert.AreEqual(0, collection[0]); Assert.AreEqual(3, collection[1]); }
public void TestSortIsSortedWithListSort() { List<int> collection = new List<int>() { 3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23 }; MergeSorter<int> sorter = new MergeSorter<int>(); sorter.Sort(collection); List<int> collection2 = new List<int>() { 3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23 }; collection2.Sort(); CollectionAssert.AreEqual(collection2, collection); }
public void TestWithOddNumberOfItems() { List<int> collection = new List<int>(); collection.Add(3); collection.Add(0); collection.Add(11); collection.Add(-3); collection.Add(5); collection.Add(0); collection.Add(4); MergeSorter<int> sorter = new MergeSorter<int>(); sorter.Sort(collection); Assert.AreEqual(7, collection.Count); Assert.IsTrue(SortableCollection<int>.IsSorted(collection)); }
public void MergeSorterSortInt() { int[] s = new int[6]; s[0] = 3; s[1] = 2; s[2] = 4; s[3] = 1; s[4] = 0; s[5] = 5; MergeSorter<int> ms = new MergeSorter<int>(); int[] sorted_s = ms.Sort(s); Assert.AreEqual(sorted_s[0], 0); Assert.AreEqual(sorted_s[1], 1); Assert.AreEqual(sorted_s[2], 2); Assert.AreEqual(sorted_s[3], 3); Assert.AreEqual(sorted_s[4], 4); Assert.AreEqual(sorted_s[5], 5); }
public void TestSortIsSortedWithCheck() { List<int> collection = new List<int>() { 3, 5, 21, 543, 2, 12, 3, 65, 34, 234, 23, 12, 3, 43, 12, 32, 341, 24, 23 }; MergeSorter<int> sorter = new MergeSorter<int>(); sorter.Sort(collection); bool isSorted = true; for (int i = 0; i < collection.Count - 1; i++) { if (collection[i] > collection[i + 1]) { isSorted = false; } } Assert.IsTrue(isSorted); }
public void TestNullList() { var sorter = new MergeSorter(); sorter.Sort<int>(null); }
public void TestWithANullCollection() { List<int> collection = null; MergeSorter<int> sorter = new MergeSorter<int>(); sorter.Sort(collection); }
public void MergeSortTestWithOneMemberArray() { MergeSorter<int> mergesorter = new MergeSorter<int>(); IList<int> list = new List<int>() { 1, }; IList<int> sortedList = new List<int>() { 1, }; mergesorter.Sort(list); Assert.AreEqual(string.Join(",", sortedList), string.Join(",", list)); }
public void MergeSortTestWithFilledArrayOddRecords() { MergeSorter<int> mergesorter = new MergeSorter<int>(); IList<int> list = new List<int>() { 9, 3, 2, 1, 4, 6, 5, 0, 8, 7, 10 }; IList<int> sortedList = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; mergesorter.Sort(list); Assert.AreEqual(string.Join(",", sortedList), string.Join(",", list)); }