public void GenerateRandomArrayTests(int count, double maxValue) { var generator = new ArrayGenerator(); var array = generator.GenerateRandomArray(count, maxValue); Assert.AreEqual(count, array.Length); Assert.That(array, Is.All.InRange(0d, maxValue)); Assert.AreEqual(1d, array.Sum(), Delta); }
static void Main(string[] args) { int size = 1000; int[] array = ArrayGenerator.GenerateRandomArray(size); int[] ascendingArray = ArrayGenerator.GenerateSortedAscendingArray(size); int[] descendingArray = ArrayGenerator.GenerateSortedDescendingArray(size); int[] vShapedArray = ArrayGenerator.GenerateVShapeArray(size); int[] constantArray = ArrayGenerator.GenerateConstantArray(size); int[] aShapeArray = ArrayGenerator.GenerateAShapeArray(size); Stopwatch sw = Stopwatch.StartNew(); int high = array.Length; AdvancedSortingAlgorithm.QuickSort(array, 0, high - 1); sw.Stop(); Console.WriteLine("Time taken random: {0}ms", sw.Elapsed.TotalMilliseconds); Stopwatch sw1 = Stopwatch.StartNew(); AdvancedSortingAlgorithm.QuickSort(descendingArray, 0, high - 1); sw1.Stop(); Console.WriteLine("Time taken desc: {0}ms", sw1.Elapsed.TotalMilliseconds); Stopwatch sw2 = Stopwatch.StartNew(); AdvancedSortingAlgorithm.QuickSort(vShapedArray, 0, high - 1); sw2.Stop(); Console.WriteLine("Time taken V: {0}ms", sw2.Elapsed.TotalMilliseconds); Stopwatch sw3 = Stopwatch.StartNew(); AdvancedSortingAlgorithm.QuickSort(aShapeArray, 0, high - 1); sw3.Stop(); Console.WriteLine("Time taken A: {0}ms", sw3.Elapsed.TotalMilliseconds); Stopwatch sw4 = Stopwatch.StartNew(); AdvancedSortingAlgorithm.QuickSort(constantArray, 0, high - 1); sw4.Stop(); Console.WriteLine("Time taken Const: {0}ms", sw4.Elapsed.TotalMilliseconds); }
public void GenereteRandomArray_InabilityMakeAount_ThrowsArgumentException(int count, double maxValue) { var generator = new ArrayGenerator(); Assert.Throws <ArgumentException>(() => generator.GenerateRandomArray(count, maxValue)); }