public void MatrixSortLenOperationExeptionInterface() { const int xSize = 10; int[][] matrix = new int[xSize][]; Random random = new Random(); for (int i = 0; i < xSize; i++) { int ySize = random.Next(1, 11); if (i == 4) { continue; } matrix[i] = new int[ySize]; for (int j = 0; j < ySize; j++) { matrix[i][j] = random.Next(-1000, 1000); } } ArrayLenComparer comparer = new ArrayLenComparer(); MatrixSort.Sort(matrix, comparer); }
public void MatrixSortAbsInterface() { const int xSize = 10; int[][] matrix = new int[xSize][]; Random random = new Random(); for (int i = 0; i < xSize; i++) { int ySize = random.Next(1, 11); matrix[i] = new int[ySize]; for (int j = 0; j < ySize; j++) { matrix[i][j] = random.Next(-1000, 1000); } } int[][] matrix1 = (Int32[][])matrix.Clone(); AbsMaxArrayComparer comparer = new AbsMaxArrayComparer(); MatrixSort.Sort(matrix, comparer); Comparison <int[]> sysComparer = comparer.Comparer; Array.Sort <int[]>(matrix1, sysComparer); CollectionAssert.AreEqual(matrix, matrix1); }
public void MatrixSortLenInterface() { const int xSize = 10; int[][] matrix = new int[xSize][]; Random random = new Random(); for (int i = 0; i < xSize; i++) { int ySize = random.Next(1, 11); matrix[i] = new int[ySize]; for (int j = 0; j < ySize; j++) { matrix[i][j] = random.Next(-1000, 1000); } } ArrayLenComparer comparer = new ArrayLenComparer(); MatrixSort.Sort(matrix, comparer); for (int i = 1; i < matrix.Length; i++) { if (matrix[i].Length < matrix[i - 1].Length) { Assert.Fail("Error arrary[" + i + "] length < " + "arrary[" + (i - 1) + "] length"); } } }
public void MatrixSortAbsOperationExeption() { const int xSize = 10; int[][] matrix = new int[xSize][]; Random random = new Random(); for (int i = 0; i < xSize; i++) { int ySize = random.Next(1, 11); if (i == 4) { continue; } matrix[i] = new int[ySize]; for (int j = 0; j < ySize; j++) { matrix[i][j] = random.Next(-1000, 1000); } } Func <int[], int[], int> comparer = (i, j) => i.Max((k) => Math.Abs(k)) - j.Max((k) => Math.Abs(k)); MatrixSort.Sort(matrix, comparer); }
public void MatrixSortAbsArgumentNullExeptionInterface() { int[][] matrix = null; AbsMaxArrayComparer comparer = new AbsMaxArrayComparer(); MatrixSort.Sort(matrix, comparer); }
public void MatrixSortAbsArgumentNullExeption() { int[][] matrix = null; Func <int[], int[], int> comparer = (i, j) => i.Max((k) => Math.Abs(k)) - j.Max((k) => Math.Abs(k)); MatrixSort.Sort(matrix, comparer); }
public void Sort_MatrixRowIsNull_ThrowsArgumentNullException() { var nullRowArray = new int[4][]; Assert.That(() => MatrixSort.Sort(nullRowArray, descRowSumCompare), Throws.ArgumentNullException. With.Message.EqualTo("Value cannot be null.\r\nParameter name: matrix[0]")); }
public void TestMinSortDescending() { var array = new int[, ] { { 0, 2 }, { 3, 1 } }; var expected = new int[, ] { { 3, 1 }, { 0, 2 } }; MatrixSort.Sort(array, MatrixSort.Criteria.Min, true); CollectionAssert.AreEqual(expected, array); }
public void TestMaxSortAscending() { var array = new int[, ] { { 1, 2 }, { 3, 1 } }; var expected = new int[, ] { { 1, 2 }, { 3, 1 } }; MatrixSort.Sort(array, MatrixSort.Criteria.Max, false); CollectionAssert.AreEqual(expected, array); }
public void MatrixSortAbs() { const int xSize = 10; int[][] matrix = new int[xSize][]; Random random = new Random(); for (int i = 0; i < xSize; i++) { int ySize = random.Next(1, 11); matrix[i] = new int[ySize]; for (int j = 0; j < ySize; j++) { matrix[i][j] = random.Next(-1000, 1000); } } int[][] matrix1 = (Int32[][])matrix.Clone(); Func <int[], int[], int> comparer = (i, j) => i.Max((k) => Math.Abs(k)) - j.Max((k) => Math.Abs(k)); MatrixSort.Sort(matrix, comparer); Comparison <int[]> sysComparer = (i, j) => { if (i.Max((k) => Math.Abs(k)) > j.Max((k) => Math.Abs(k))) { return(1); } else if (i.Max((k) => Math.Abs(k)) < j.Max((k) => Math.Abs(k))) { return(-1); } else { return(0); } }; Array.Sort <int[]>(matrix1, sysComparer); CollectionAssert.AreEqual(matrix, matrix1); }
public void MatrixSortSumComparerNullExeptionInterface() { const int xSize = 10; int[][] matrix = new int[xSize][]; Random random = new Random(); for (int i = 0; i < xSize; i++) { int ySize = random.Next(1, 11); matrix[i] = new int[ySize]; for (int j = 0; j < ySize; j++) { matrix[i][j] = random.Next(-1000, 1000); } } int[][] matrix1 = (Int32[][])matrix.Clone(); SumArrayComparer comparer = null; MatrixSort.Sort(matrix, comparer); }
public void Sort_AscRowSum_SortsCorrectly() { MatrixSort.Sort(array, (first, second) => first.Sum() > second.Sum()); var expected = new int[4][] { new int[3] { 9, 0, 1 }, //Min 0, Max 9, Sum 11 new int[3] { 10, 2, 1 }, //Min 1, Max 10, Sum 13 new int[3] { 7, 3, 4 }, //Min 3, Max 7, Sum 14 new int[3] { 8, 5, 6 } //Min 5, Max 8, Sum 19 }; Assert.That(array, Is.EqualTo(expected)); }
public void Sort_DescRowSum_SortsCorrectly() { MatrixSort.Sort(array, descRowSumCompare); var expected = new int[4][] { new int[3] { 8, 5, 6 }, //Min 5, Max 8, Sum 19 new int[3] { 7, 3, 4 }, //Min 3, Max 7, Sum 14 new int[3] { 10, 2, 1 }, //Min 1, Max 10, Sum 13 new int[3] { 9, 0, 1 } //Min 0, Max 9, Sum 11 }; Assert.That(array, Is.EqualTo(expected)); }
public void Sort_FuncIsNull_ThrowsArgumentNullException() { Assert.That(() => MatrixSort.Sort(array, null), Throws.ArgumentNullException. With.Message.EqualTo("Value cannot be null.\r\nParameter name: compare")); }
public void Sort_MatrixIsNull_ThrowsArgumentNullException() { Assert.That(() => MatrixSort.Sort(null, descRowSumCompare), Throws.ArgumentNullException. With.Message.EqualTo("Value cannot be null.\r\nParameter name: matrix")); }