public void RadixSort_Stress_Test() { int[] randomNumbers; int nodeCount = 1000 * 1000; var rnd = new Random(); randomNumbers = Enumerable.Range(1, nodeCount) .OrderBy(x => rnd.Next()) .ToArray(); var timer = new Stopwatch(); timer.Start(); var result = RadixSort.Sort(randomNumbers); timer.Stop(); Debug.WriteLine($"sorted {nodeCount} integers using radix sort in {timer.ElapsedMilliseconds} milliseconds."); for (int i = 1; i <= nodeCount; i++) { Assert.AreEqual(i, result[i - 1]); } }
SortingResult PerformRadixSort(float[] input) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); if (sort == null) { sort = new RadixSort(); sort.SetupBuffers(input.Length, radixSortShader); } sort.Sort(input); sort.GetData(input); stopWatch.Stop(); bool isSorted = RadixDemoUtilities.SortingCheck(input); return(new SortingResult() { sortingName = "Radix Sort", averageTimeTaken = stopWatch.ElapsedMilliseconds, isCorrectlySorted = isSorted, message = isSorted ? "" : "Wrongly sorted at: " + input.Length }); }
public void SortingTest() { Action <int[]>[] actions = new Action <int[]>[] { BubbleSort.Sort, data => BucketSort.Sort(data, SortingTests.MaxValue), data => CountingSort.Sort(data, SortingTests.MaxValue), HeapSort.Sort, InsertionSort.Sort, MergeSort.Sort, QuickSort.Sort, data => RadixSort.Sort(data, SortingTests.MaxValue), }; for (int i = 0; i < 10; i++) { for (int j = 0; j < 100; j++) { int[] data = ArrayUtilities.CreateRandomArray(j, 0, SortingTests.MaxValue); int[][] results = new int[actions.Length][]; for (int k = 0; k < actions.Length; k++) { results[k] = new int[data.Length]; Array.Copy(data, results[k], data.Length); actions[k](results[k]); Assert.IsTrue(ArrayUtilities.AreEqual(results[k], results[0])); } } } }
public void InsertionSort_Test() { // Arrange var collectionInsertion = new Collection <int>(); var collectionMerge = new Collection <int>(); var collectionHeap = new Collection <int>(); var collectionRadix = new Collection <int>(); Random random = new Random(); // Act for (int i = 0; i < 1000; i++) { var number = random.Next(0, 10000); collectionInsertion.Add(number); collectionMerge.Add(number); collectionHeap.Add(number); collectionRadix.Add(number); } InsertionSort <int> .Sort(collectionInsertion); collectionMerge = MergeSort <int> .Sort(collectionMerge); HeapSort <int> .Sort(collectionHeap); RadixSort.Sort(collectionRadix); // Assert for (int i = 0; i < collectionInsertion.Count; i++) { Assert.AreEqual(collectionInsertion[i], collectionMerge[i]); Assert.AreEqual(collectionHeap[i], collectionMerge[i]); Assert.AreEqual(collectionRadix[i], collectionHeap[i]); } }
public void RadixSortLargeRandomArrayTest() { int[] arr = { 8586, 4916, 5843, 4589, 4331, 9177, -6992, 8780, 8948, -4101, -8390, 8900, 3165, -5036, 5136, -420, 3868, 9700, 3924, -3041, -4483, -8856, -3565, -4697, 1812, 2103, -8455, 8361, -2569, 8488, 6245, 6304, -8980, -3969, -422, 1273, -6731, -2400, 4409, -9780, -2776, -533, 7970, 9449, 1908, -5483, -8328, 4147, 4112, -4641, 1730, -9490, 7088, -5676, -5217, 7442, -1519, 540, -7224, -7772, 7631, -5354, 1349, -9540, -347, -4694, 7880, -2866, 5385, -6138, -3690, -3733, -4710, 3704, 9734, 6050, -6827, -3015, 3394, -2706, 430, -2602, -5751, -7929, -3243, 5735, 9215, 6695, -8753, 2135, -7208, 2729, -5177, 2181, -7412, -7423, 8118, 7510, -205, -3399 }; int[] expected = { -9780, -9540, -9490, -8980, -8856, -8753, -8455, -8390, -8328, -7929, -7772, -7423, -7412, -7224, -7208, -6992, -6827, -6731, -6138, -5751, -5676, -5483, -5354, -5217, -5177, -5036, -4710, -4697, -4694, -4641, -4483, -4101, -3969, -3733, -3690, -3565, -3399, -3243, -3041, -3015, -2866, -2776, -2706, -2602, -2569, -2400, -1519, -533, -422, -420, -347, -205, 430, 540, 1273, 1349, 1730, 1812, 1908, 2103, 2135, 2181, 2729, 3165, 3394, 3704, 3868, 3924, 4112, 4147, 4331, 4409, 4589, 4916, 5136, 5385, 5735, 5843, 6050, 6245, 6304, 6695, 7088, 7442, 7510, 7631, 7880, 7970, 8118, 8361, 8488, 8586, 8780, 8900, 8948, 9177, 9215, 9449, 9700, 9734 }; var sort = new RadixSort(); var result = sort.Sort(arr); Assert.AreEqual(expected, result); }
public static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); RadixSort.Sort(input); Console.WriteLine(string.Join(" ", input)); }
private static void RadixSortTest() { var unsortedList = _testRunner.InitArray(); var radixSort = new RadixSort(); var sortedList = radixSort.Sort(unsortedList); Debug.Assert(_testRunner.Verify(sortedList)); }
static void Main(string[] args) { int[] arr = new int[] { 5, 2, 3, 8, 1, 2, 15, 23, 55, 66, 22, 15, 45 }; arr.Write(); RadixSort.Sort(arr); arr.Write(); Console.ReadLine(); }
public void Sort() { int[] arr = new int[] { 170, 45, 75, 90, 802, 24, 2, 66 }; int[] resultArr = new int[] { 2, 24, 45, 66, 75, 90, 170, 802 }; RadixSort radixSort = new RadixSort(); radixSort.Sort(arr); Assert.Equal(resultArr, arr); }
public void RadixSort_Smoke_Test() { var result = RadixSort.Sort(TestArray); for (int i = 0; i < TestArray.Length; i++) { Assert.AreEqual(i, result[i]); } }
public void RadixSort_Descending_Smoke_Test() { var result = RadixSort.Sort(testArray, SortDirection.Descending); for (int i = 0; i < testArray.Length; i++) { Assert.AreEqual(testArray.Length - i - 1, result[i]); } }
private void RadixSortImplementation() { int len = 8; int range = len * len; int[] input = new int[len]; int[] output = new int[len]; Console.WriteLine("Radix Sort: "); RadixSort s = new RadixSort(); input = Utility.GetInputData(len, range); Utility.PrintAll("Input: ", input); output = s.Sort(input, range, SortOrderType.Asc); Utility.PrintAll("Output: ", input); output = s.Sort(input, range, SortOrderType.Desc); Utility.PrintAll("Output: ", input); }
public void SortWithEmptyArray() { int[] arr = new int[] {}; int[] resultArr = new int[] {}; RadixSort radixSort = new RadixSort(); radixSort.Sort(arr); Assert.Equal(resultArr, arr); }
public void RadixSortSimpleArrayTest() { int[] expected = { 10, 14, 22, 1000, 1500, 2000, 2001, 2002, 2003 }; int[] arr = { 22, 1500, 2001, 2002, 1000, 2000, 2003, 10, 14 }; var sort = new RadixSort(); var result = sort.Sort(arr); Assert.AreEqual(expected, result); }
public void TestRadixSort() { var result = new int[_size]; Array.Copy(_unsorted, result, _size); RadixSort.Sort(result, RadixSort.RadixSortType.Lsd); for (int i = 0; i < result.Length; i++) { Assert.AreEqual(_sorted[i], result[i]); } }
public void WhenWeGiveArray_ThenItIsSorted() { int[] array = { 2, 4, 1, 5, 6, 8, 3, 9, 7 }; RadixSort.Sort(array); int i = 1; foreach (int v in array) { Assert.AreEqual(i, v); i++; } }
public void RadixSortTest() { int[] result = CreateResultArray(); RadixSort sort = new RadixSort(result); result = sort.Sort(); for (int i = 0; i < array.Length; i++) { Assert.AreEqual(expected[i], result[i]); } }
public void Test(int[] data) { // Arrange int[] data2 = new int[data.Length]; Array.Copy(data, data2, data.Length); Array.Sort(data2); var sorter = new RadixSort(); // Act sorter.Sort(data); // Assert CollectionAssert.AreEqual(data, data2); }
public void RadixSortMSDTest() { // arrange var radixSort = new RadixSort <int>(Items); // act radixSort.Sort(false); // assert for (int i = 0; i < Items.Count; i++) { Assert.AreEqual(Sorted[i], radixSort.Items[i]); } }
public void RadixSort_Ascending_Stress_Test() { var rnd = new Random(); var nodeCount = 1000; var randomNumbers = Enumerable.Range(1, nodeCount) .OrderBy(x => rnd.Next()) .ToList(); var result = RadixSort.Sort(randomNumbers.ToArray()); for (int i = 1; i <= nodeCount; i++) { Assert.AreEqual(i, result[i - 1]); } }
public void RadixSort_Descending_Stress_Test() { var rnd = new Random(); var nodeCount = 1000; var randomNumbers = Enumerable.Range(1, nodeCount) .OrderBy(x => rnd.Next()) .ToList(); var result = RadixSort.Sort(randomNumbers.ToArray(), SortDirection.Descending); for (int i = 0; i < nodeCount; i++) { Assert.AreEqual(randomNumbers.Count - i, result[i]); } }
public static void RadixSortTest() { int[] array = { 64, 8, 216, 512, 27, 729, 0, 1, 343, 125 }; int[] array2 = { 278, 109, 63, 930, 589, 184, 505, 269, 8, 83 }; int[] array3 = array.Union(array2).ToArray(); int[] result = null; int m = 3; RadixSort sort = new RadixSort(); result = sort.Sort(array3, m); foreach (int num in result) { System.Console.Write(num + " "); } }
public void TestSortingShortsGeneric() { var shorts = new List <short> { 3, 5, 1, 8, 2 }; var radixSort = new RadixSort <short>(new Calculator <short>()); shorts = radixSort.Sort(shorts); var expected = new List <short> { 1, 2, 3, 5, 8 }; Assert.AreEqual(expected.Count, shorts.Count); CollectionAssert.AreEqual(expected, shorts); }
public void TestSortingBytesGeneric() { var bytes = new List <byte> { 3, 5, 1, 8, 2 }; var radixSort = new RadixSort <byte>(new Calculator <byte>()); bytes = radixSort.Sort(bytes); var expected = new List <byte> { 1, 2, 3, 5, 8 }; Assert.AreEqual(expected.Count, bytes.Count); CollectionAssert.AreEqual(expected, bytes); }
public void TestSortingULongsGeneric() { var ulongs = new List <ulong> { 3, 5, 1, 8, 2 }; var radixSort = new RadixSort <ulong>(new Calculator <ulong>()); ulongs = radixSort.Sort(ulongs); var expected = new List <ulong> { 1, 2, 3, 5, 8 }; Assert.AreEqual(expected.Count, ulongs.Count); CollectionAssert.AreEqual(expected, ulongs); }
public void TestSortingCharsGeneric() { // TODO: Not yet implemented behaviour for non-integral type sorting var chars = new List <char> { 'h', 'q', 'a', 'y', 'n' }; var radixSort = new RadixSort <char>(new Calculator <char>()); chars = radixSort.Sort(chars); var expected = new List <char> { 'a', 'h', 'n', 'q', 'y' }; Assert.AreEqual(expected.Count, chars.Count); CollectionAssert.AreEqual(expected, chars); }
public void TestSortingDecimalsGeneric() { // TODO: Not yet implemented behaviour for non-integral type sorting var decimals = new List <decimal> { 3, 5, 1, 8, 2 }; var radixSort = new RadixSort <decimal>(new Calculator <decimal>()); decimals = radixSort.Sort(decimals); var expected = new List <decimal> { 1, 2, 3, 5, 8 }; Assert.AreEqual(expected.Count, decimals.Count); CollectionAssert.AreEqual(expected, decimals); }
public void TestSortingFloatsGeneric() { // TODO: Not yet implemented behaviour for non-integral type sorting var floats = new List <float> { 3, 5, 1, 8, 2 }; var radixSort = new RadixSort <float>(new Calculator <float>()); floats = radixSort.Sort(floats); var expected = new List <float> { 1, 2, 3, 5, 8 }; Assert.AreEqual(expected.Count, floats.Count); CollectionAssert.AreEqual(expected, floats); }
public void TestSortingIntsNonGeneric() { var ints = new List <int> { 3, 5, 1, 8, 2 }; ints = RadixSort.Sort(ints); var expected = new List <int> { 1, 2, 3, 5, 8 }; Assert.AreEqual(expected.Count, ints.Count); for (int i = 0; i < ints.Count; i++) { Assert.AreEqual(expected[i], ints[i]); } }
public void RadixSort_Test() { // Arrange var collection = new Collection <int>(); Random random = new Random(); // Act for (int i = 0; i < 1000; i++) { collection.Add(random.Next(0, 10000)); } RadixSort.Sort(collection); // Assert int prevElement = -10001; foreach (var element in collection) { Assert.IsTrue(element >= prevElement); prevElement = element; } }