public void NullArraySelectionSortTest() { var selectionSort = new SelectionSort <int>(); int[] array = null; Assert.Throws <ArgumentException>(() => selectionSort.Run(array)); }
public void Run_should_not_fail_when_the_same_value_appears_multiple_times() { var array = new int[] { 50, 3, 25, 3, 40, 3 }; var result = SelectionSort.Run(array); array.SequenceEqual(new int[] { 3, 3, 3, 25, 40, 50 }).Should().BeTrue(); }
public void Run_should_sort_array() { var array = new int[] { 50, 430, 1, 3, 9, 2, 34, 100, 440, 430, 21 }; var result = SelectionSort.Run(array); array.SequenceEqual(new int[] { 1, 2, 3, 9, 21, 34, 50, 100, 430, 430, 440 }).Should().BeTrue(); }
public void SelectionSortAscendingTest() { var selectionSort = new SelectionSort <int>(); var array = new[] { 5, 2, 4, 7, 1, 3, 1, 6 }; selectionSort.Run(array); Assert.IsTrue(array.IsSortedAscending()); }
public void Run_should_not_fail_on_single_element_array() { var array = new int[] { 50 }; var result = SelectionSort.Run(array); array.Length.Should().Be(1); array[0].Should().Be(50); }
public void Run_should_not_fail_on_empty_array() { var array = new int[] { }; var result = SelectionSort.Run(array); array.Should().NotBeNull(); array.Should().BeEmpty(); }
/// <summary> /// Testet alle Mechanismen mit den selben Zahlen und schaut welcher am schnellsten ist (Quick) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonTestAll_Click(object sender, EventArgs e) { Random random = new Random(); numbers = new int[100000]; for (int x = 0; x < 100000; x++) { numbers[x] = random.Next(1, 100); } sw.Start(); BubbleSort bubbleSort = new BubbleSort(); bubbleSort.Run(numbers); sw.Stop(); textBoxLog.Text += "BubbleSort Testing Zeit: " + sw.Elapsed + "\r\n"; Console.WriteLine("BubbleSort Testing - Zeit: " + sw.Elapsed); sw.Reset(); sw.Start(); InsertionSort insertionSort = new InsertionSort(); insertionSort.Run(numbers); sw.Stop(); textBoxLog.Text += "InsertionSort Testing Zeit: " + sw.Elapsed + "\r\n"; Console.WriteLine("InsertionSort Testing - Zeit: " + sw.Elapsed); sw.Reset(); sw.Start(); SelectionSort selectionSort = new SelectionSort(); selectionSort.Run(numbers); sw.Stop(); textBoxLog.Text += "SelectionSort Testing Zeit: " + sw.Elapsed + "\r\n"; Console.WriteLine("SelectionSort Testing - Zeit: " + sw.Elapsed); sw.Reset(); sw.Start(); QuickSort quickSort = new QuickSort(); quickSort.Run(numbers); sw.Stop(); textBoxLog.Text += "QuickSort Testing Zeit: " + sw.Elapsed + "\r\n"; Console.WriteLine("QuickSort Testing - Zeit: " + sw.Elapsed); sw.Reset(); }
private object RunIterationsTiming(int arraySize) { var array = new int[arraySize]; var rand = new Random(); for (var i = 0; i < arraySize; i++) { array[i] = rand.Next(1000); } var stopWatch = new Stopwatch(); stopWatch.Start(); SelectionSort.Run(array); stopWatch.Stop(); return(stopWatch.ElapsedMilliseconds); }
/// <summary> /// Testet ob der Selection Sort Mechanismus funktioniert /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonSelectionTest_Click(object sender, EventArgs e) { sw.Start(); bool valid = true; Random random = new Random(); for (int i = 0; i < 1000; i++) { numbers = new int[3000]; for (int x = 0; x < 3000; x++) { numbers[x] = random.Next(100, 100000); } SelectionSort selectionSort = new SelectionSort(); int[] array = selectionSort.Run(numbers); valid = testing.Run(array); } sw.Stop(); textBoxLog.Text += "Selection Testing Zeit: " + sw.Elapsed + "\r\n"; Console.WriteLine("Selection Testing - Zeit: " + sw.Elapsed); Console.WriteLine("Valid: " + valid); sw.Reset(); }
/// <summary> /// Sortiert die eingebenen Zahlen mithilfe des Selection Sorts /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonSelection_Click(object sender, EventArgs e) { numbers = GetArrayFromForm(); sw.Start(); SelectionSort selectionSort = new SelectionSort(); StringBuilder stringBuilder = new StringBuilder(); int[] array = selectionSort.Run(numbers); sw.Stop(); foreach (var element in array) { stringBuilder.Append(element.ToString() + " "); } textBoxOutput.Text = stringBuilder.ToString(); if (checkBoxTesting.Checked) { labelValid.Text = "Valid: " + testing.Run(array).ToString(); } textBoxLog.Text += "Selection Zeit: " + sw.Elapsed + "\r\n"; Console.WriteLine("Selection Zeit: " + sw.Elapsed); sw.Reset(); }