public void Testing_NullComparerParameter_Throwing_ArgumentNulleException() { int[][] Matrix = new int[4][]; Matrix[0] = new int[] { 2, 5, 8, 7, 12, 74 }; //2 Matrix[1] = new int[] { 5, 4, 10, 3, 15 }; //3 Matrix[2] = new int[] { 13, 25, 85, 95, 112, 544 }; //13 Matrix[3] = new int[] { 1, 2, 21, 45, 10 }; //1 int[] keys = { }; BubbleSortDelegate.SortRows(Matrix, Strategy.GetMaxRowsElements(Matrix), new Comparison <int>((a, b) => a.CompareTo(b))); }
/// <summary> /// Performs sorting of the array. /// </summary> /// <param name="array">Input array.</param> /// <param name="sortBy">Sorting type, see <see cref="SortCriteria"/> enum.</param> /// <returns>New sorted array.</returns> public int[,] SortMatrix(int[,] array, SortCriteria sortBy) { int[,] currentArray = (int[, ])array.Clone(); this.xMax = currentArray.GetUpperBound(1); this.yMax = currentArray.GetUpperBound(0); GetValueOfRow GetRowValue = null; BubbleSortDelegate BubbleSort = null; switch (sortBy) { // normal sorting order case SortCriteria.RowSum: GetRowValue = GetRowValueRowSum; BubbleSort = BubbleSortNormal; break; case SortCriteria.RowMax: GetRowValue = GetRowValueRowMax; BubbleSort = BubbleSortNormal; break; case SortCriteria.RowMin: GetRowValue = GetRowValueRowMin; BubbleSort = BubbleSortNormal; break; // reverse sorting order case SortCriteria.RowSumReverse: GetRowValue = GetRowValueRowSumReverse; BubbleSort = BubbleSortReverse; break; case SortCriteria.RowMaxReverse: GetRowValue = GetRowValueRowMaxReverse; BubbleSort = BubbleSortReverse; break; case SortCriteria.RowMinReverse: GetRowValue = GetRowValueRowMinReverse; BubbleSort = BubbleSortReverse; break; } BubbleSort(currentArray, GetRowValue); return(currentArray); }
public void Testing_DecreasingMinElements_Success() { int[][] Matrix = new int[4][]; Matrix[0] = new int[] { 2, 5, 8, 7, 12, 74 }; //2 Matrix[1] = new int[] { 5, 4, 10, 3, 15 }; //3 Matrix[2] = new int[] { 13, 25, 85, 95, 112, 544 }; //13 Matrix[3] = new int[] { 1, 2, 21, 45, 10 }; //1 BubbleSortDelegate.SortRows(Matrix, Strategy.GetMinRowsElements(Matrix), new Comparison <int>((a, b) => b.CompareTo(a))); int[][] expected = new int[4][]; expected[3] = new int[] { 1, 2, 21, 45, 10 }; expected[2] = new int[] { 2, 5, 8, 7, 12, 74 }; expected[1] = new int[] { 5, 4, 10, 3, 15 }; expected[0] = new int[] { 13, 25, 85, 95, 112, 544 }; for (int i = 0; i < expected.Length; i++) { CollectionAssert.AreEqual(Matrix[i], expected[i]); } }
public void Testing_IncreasingMaxElements_Success() { int[][] Matrix = new int[4][]; Matrix[0] = new int[] { 2, 5, 8, 7, 12, 74 }; //74 Matrix[1] = new int[] { 3, 4, 9, 2, 15 }; //15 Matrix[2] = new int[] { 13, 25, 85, 95, 112, 544 }; //544 Matrix[3] = new int[] { 3, 21, 45, 10 }; //45 BubbleSortDelegate.SortRows(Matrix, Strategy.GetMaxRowsElements(Matrix), new Comparison <int>((a, b) => a.CompareTo(b))); int[][] expected = new int[4][]; expected[0] = new int[] { 3, 4, 9, 2, 15 }; expected[1] = new int[] { 3, 21, 45, 10 }; expected[2] = new int[] { 2, 5, 8, 7, 12, 74 }; expected[3] = new int[] { 13, 25, 85, 95, 112, 544 }; for (int i = 0; i < expected.Length; i++) { CollectionAssert.AreEqual(Matrix[i], expected[i]); } }
public void BubbleSortDelegate_ArgumentNullException(Func <int[][]> func) { int[][] array = func(); int[] keys = null; Assert.Throws <ArgumentNullException>(() => BubbleSortDelegate.SortRows(array, keys, new Comparison <int>((a, b) => a.CompareTo(b)))); }
public int[][] BubbleSortDelegate_ByMinElemntsRowsDesc_CorrectValues(Func <int[][]> func) { int[][] array = func(); BubbleSortDelegate.SortRows(array, KeysForSort.GetMinRowsElements(array), new Comparison <int>((a, b) => b.CompareTo(a))); return(array); }
public int[][] BubbleSortDelegate_ByMinElemntsRows_Succed(Func <int[][]> func) { int[][] array = func(); BubbleSortDelegate.SortRows(array, KeysForSort.GetMinRowsElements(array), new Comparison <int>((a, b) => a.CompareTo(b))); return(array); }
public int[][] BubbleSortDelegate_BySumElemntsRowsDesc_Succed(Func <int[][]> func) { int[][] array = func(); BubbleSortDelegate.SortRows(array, KeysForSort.GetSumRowsElements(array), new Comparison <int>((a, b) => b.CompareTo(a))); return(array); }
public void Sort_ArgumentNullExceptionTests(int[][] sourceArray, Comparison <int[]> comparator) { Assert.Throws <ArgumentNullException>(() => BubbleSortDelegate.Sort(sourceArray, comparator)); }
public int[][] Sort_SortesArrayUsingInterfaceTests(int[][] sourceArray, IComparer <int[]> comparator) { BubbleSortDelegate.Sort(sourceArray, comparator); return(sourceArray); }
public int[][] Sort_SortesArrayUsingDelegateTests(int[][] sourceArray, Comparison <int[]> comparator) { BubbleSortDelegate.Sort(sourceArray, comparator); return(sourceArray); }