public void BubbleSortByMin_Descending_Test() { int[][] array1 = new int[][] { new int[] { 5, 12, -3 }, new int[] { 0, 3 }, new int[] { 7, 8, 9, 7 } }; int[][] sorted = new int[][] { new int[] { 7, 8, 9, 7 }, new int[] { 5, 12, -3 }, new int[] { 0, 3 } }; SortArray.BubbleSort(array1, new SortDescendingByMinElemRow()); CollectionAssert.AreEquivalent(sorted, array1); }
public void BubbleSortByMinDescending_UsingDelegate_Test() { int[][] array1 = new int[][] { new int[] { 5, 12, -3 }, new int[] { 0, 3 }, new int[] { 7, 8, 9, 7 } }; int[][] sorted = new int[][] { new int[] { 7, 8, 9, 7 }, new int[] { 5, 12, -3 }, new int[] { 0, 3 } }; var comparer = new AdapterForDelegate(new SortDescendingByMinElemRow().Compare); SortArray.BubbleSort(array1, new SortDescendingByMinElemRow()); CollectionAssert.AreEquivalent(sorted, array1); }
public void BubbleSortTest_AcceptsArrayLength_ThrowsException() { int[][] array1 = new int[1][]; int[][] array2 = new int[1][]; int[][] array3 = new int[][] { }; int[][] array4 = new int[][] { }; SortArray.BubbleSort(array1, new SortDescendingByMaxElemRow()); SortArray.BubbleSort(array3, new SortAscendingRowBySum()); CollectionAssert.AreEquivalent(array1, array2); CollectionAssert.AreEquivalent(array3, array4); }
public static void Main(string[] args) { int[] array = new int[10] { 3, 6, 1, 8, 2, 5, 9, 2, 7, 4 }; //Bubble Sort SortArray <int> .BubbleSort(array); Console.Write("Result of Bubble Sort:"); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } Console.WriteLine(); //Insertion Sort SortArray <int> .InsertionSort(array); Console.Write("Result of Insertion Sort:"); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } Console.WriteLine(); //Selection Sort SortArray <int> .SelectionSort(array); Console.Write("Result of Selection Sort:"); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } Console.WriteLine(); //Merge Sort SortArray <int> .MergeSort(array); Console.Write("Result of Merge Sort:"); for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + " "); } }
static void Main() { SortArray sortArray = new SortArray(); Console.WriteLine("1"); sortArray.SortAscendingRowBySum(ref array); PrinArray(array); Console.WriteLine(); Console.WriteLine("2"); sortArray.SortDescendingRowBySum(ref array); PrinArray(array); Console.WriteLine(); Console.WriteLine("3"); sortArray.SortAscendingByMinElemRow(ref array); PrinArray(array); Console.WriteLine(); Console.WriteLine("4"); sortArray.SortDescendingByMinElemRow(ref array); PrinArray(array); Console.WriteLine(); Console.WriteLine("5"); sortArray.SortAscendingByMaxElemRow(ref array); PrinArray(array); Console.WriteLine(); Console.WriteLine("6"); sortArray.SortDescendingByMaxElemRow(ref array); PrinArray(array); PrinArray(SortArray.BubbleSort(array1, new SortDescendingByMaxElemRow())); Console.WriteLine(); Console.ReadKey(); }
public void BubbleSortTest_AcceptsEmptyArray_ThrowsException(int[][] array) { Assert.Throws <ArgumentNullException>(() => SortArray.BubbleSort(array, new SortAscendingByMaxElemRow())); }