diff --git a/Lab6/Purple.cs b/Lab6/Purple.cs index 231c75b5..e982fb22 100644 --- a/Lab6/Purple.cs +++ b/Lab6/Purple.cs @@ -1,16 +1,19 @@ -using System; +using System; +using System; using System.Security.Cryptography; using static System.Runtime.InteropServices.JavaScript.JSType; -namespace Lab6 -{ - public class Purple - { - public void Task1(int[,] A, int[,] B) +@@ -10,47 +10,100 @@ public void Task1(int[,] A, int[,] B) { // code here + if (A.GetLength(0) == A.GetLength(1) && B.GetLength(0) == B.GetLength(1) && A.GetLength(0) == B.GetLength(0)) + { + int AMax = FindDiagonalMaxIndex(A); + int BMax = FindDiagonalMaxIndex(B); + SwapRowColumn(A, AMax, B, BMax); + } // end } @@ -19,6 +22,45 @@ public void Task2(ref int[,] A, int[,] B) // code here + if (A.GetLength(1) == B.GetLength(0)) + { + int maxRow = 0, maxCol = 0, temp = 0; + for (int i = 0; i < B.GetLength(0); i++) + { + for (int j = 0; j < B.GetLength(1); j++) + { + if (B[i, j] > 0) + { + temp++; + } + } + } + if (temp > 0) + { + int MaxR = 0; + for (int i = 0; i < A.GetLength(0); i++) + { + temp = CountPositiveElementsInRow(A, i); + if (temp > MaxR) + { + MaxR = temp; + maxRow = i; + } + } + int MaxC = 0; + for (int i = 0; i < B.GetLength(1); i++) + { + temp = CountPositiveElementsInColumn(B, i); + if (temp > MaxC) + { + MaxC = temp; + maxCol = i; + } + } + InsertColumn(ref A, maxRow, maxCol, B); + } + } + // end } @@ -27,6 +69,7 @@ public void Task3(int[,] matrix) // code here + ChangeMatrixValues(matrix); // end } @@ -36,6 +79,18 @@ public void Task4(int[,] A, int[,] B) // code here // end + int[] arrayA = CountNegativesPerRow(A); + int[] arrayB = CountNegativesPerRow(B); + int positionA = FindMaxIndex(arrayA); + int positionB = FindMaxIndex(arrayB); + if (positionA != -1 && positionB != -1 && A.GetLength(1) == B.GetLength(1)) + { + for (int i = 0; i < A.GetLength(1); i++) + { + (A[positionA, i], B[positionB, i]) = (B[positionB, i], A[positionA, i]); + } + } + // end } public void Task5(int[] matrix, Sorting sort) @@ -43,6 +98,7 @@ public void Task5(int[] matrix, Sorting sort) // code here + sort(matrix); // end } @@ -51,46 +107,785 @@ public void Task6(int[,] matrix, SortRowsByMax sort) // code here + sort(matrix); // end } - public int[] Task7(int[,] matrix, FindNegatives find) - { +@@ -59,7 +112,7 @@ public int[] Task7(int[,] matrix, FindNegatives find) int[] negatives = null; // code here + negatives = find(matrix); // end return negatives; - } - public int[,] Task8(int[,] matrix, MathInfo info) - { +@@ -69,7 +122,7 @@ public int[] Task7(int[,] matrix, FindNegatives find) int[,] answer = null; // code here + answer = info(matrix); // end return answer; - } - public int Task9(double a, double b, double h, Func func) - { +@@ -79,7 +132,7 @@ public int Task9(double a, double b, double h, Func func) int answer = 0; // code here + answer = CountSignFlips(a, b, h, func); // end return answer; - } - public void Task10(int[][] array, Action func) +@@ -88,9 +141,749 @@ public void Task10(int[][] array, Action func) { // code here + func(array); // end } + public int FindDiagonalMaxIndex(int[,] matrix) + { + int max = matrix[0, 0], maxIndex = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + if (matrix[i,i] > max) + { + max = matrix[i, i]; + maxIndex = i; + } + } + return maxIndex; + } + public void SwapRowColumn(int[,] matrix, int rowIndex, int[,] B, int columnIndex) + { + for (int i = 0; i < matrix.GetLength(0); i++) + { + (matrix[rowIndex, i], B[i, columnIndex]) = (B[i, columnIndex], matrix[rowIndex, i]); + } + } + public void InsertColumn(ref int[,] A, int rowIndex, int columnIndex, int[,] B) + { + int[,] result = new int[A.GetLength(0) + 1, A.GetLength(1)]; + for (int i = 0; i <= rowIndex; i++) + { + for (int j = 0; j < A.GetLength(1); j++) + { + result[i, j] = A[i, j]; + } + } + for (int i = 0; i < A.GetLength(1); i++) + { + result[rowIndex + 1, i] = B[i, columnIndex]; + } + for (int i = rowIndex + 1; i < A.GetLength(0); i++) + { + for (int j = 0; j < A.GetLength(1); j++) + { + result[i + 1, j] = A[i, j]; + } + } + A = result; + } + public int CountPositiveElementsInRow(int[,] matrix, int row) + { + int count = 0; + for (int i = 0; i < matrix.GetLength(1); i++) + { + if (matrix[row, i] > 0) + { + count++; + } + } + return count; + } + public int CountPositiveElementsInColumn(int[,] matrix, int col) + { + int count = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + if (matrix[i, col] > 0) + { + count++; + } + } + return count; + } + public void ChangeMatrixValues(int[,] matrix) + { + if (matrix.GetLength(0)*matrix.GetLength(1) < 5) + { + for (int i = 0; i < matrix.GetLength(0); i++) + { + for (int j = 0; j < matrix.GetLength(1); j++) + { + matrix[i, j] = matrix[i, j] * 2; + } + } + } + else + { + int[] array = new int[matrix.GetLength(0) * matrix.GetLength(1)]; + int t = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + for (int j = 0; j < matrix.GetLength(1); j++) + { + array[t] = matrix[i,j]; + t++; + } + } + int n = 1, k = array.Length; + while (n < k) + { + if (n == 0 || array[n] <= array[n - 1]) + { + n++; + } + else + { + (array[n], array[n - 1]) = (array[n - 1], array[n]); + n--; + } + } + int count = 0, k1 = 0, k2 = 0, k3 = 0, k4 = 0, k5 = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + for (int j = 0; j < matrix.GetLength(1); j++) + { + if (k1 == 0 && count < 5 && matrix[i, j] == array[0]) + { + matrix[i, j] = matrix[i, j] * 2; + count++; + k1 = 1; + } + else if (k2 == 0 && count < 5 && matrix[i, j] == array[1]) + { + matrix[i, j] = matrix[i, j] * 2; + count++; + k2 = 1; + } + else if (k3 == 0 && count < 5 && matrix[i, j] == array[2]) + { + matrix[i, j] = matrix[i, j] * 2; + count++; + k3 = 1; + } + else if (k4 == 0 && count < 5 && matrix[i, j] == array[3]) + { + matrix[i, j] = matrix[i, j] * 2; + count++; + k4 = 1; + } + else if (k5 == 0 && count < 5 && matrix[i, j] == array[4]) + { + matrix[i, j] = matrix[i, j] * 2; + count++; + k5 = 1; + } + else + matrix[i, j] = matrix[i, j] / 2; + } + } + } + } + public int[] CountNegativesPerRow(int[,] matrix) + { + int[] array = new int[matrix.GetLength(0)]; + int t = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + int count = 0; + for (int j = 0; j < matrix.GetLength(1); j++) + { + if (matrix[i, j] < 0) + { + count++; + } + } + array[t] = count; + t++; + } + return array; + } + public int FindMaxIndex(int[] array) + { + int max = 0, position = 0; + for (int i = 0; i < array.Length; i++) + { + if (array[i] > max) + { + max = array[i]; + position = i; + } + } + if (max == 0) + { + return -1; + } + else return position; + } + public void SortNegativeAscending(int[] matrix) + { + int count = 0; + for (int i = 0; i < matrix.Length; i++) + { + if (matrix[i] < 0) + { + count++; + } + } + int[] array = new int[count]; + int t = 0; + for (int i = 0; i < matrix.Length; i++) + { + if (matrix[i] < 0) + { + array[t] = matrix[i]; + t++; + } + } + int k = 1; + while (k < count) + { + if (k == 0 || array[k] > array[k - 1]) + { + k++; + } + else + { + (array[k], array[k - 1]) = (array[k - 1], array[k]); + k--; + } + } + int x = 0; + for (int i = 0; i < matrix.Length; i++) + { + if (matrix[i] < 0) + { + matrix[i] = array[x]; + x++; + } + } + } + public void SortNegativeDescending(int[] matrix) + { + int count = 0; + for (int i = 0; i < matrix.Length; i++) + { + if (matrix[i] < 0) + { + count++; + } + } + int[] array = new int[count]; + int t = 0; + for (int i = 0; i < matrix.Length; i++) + { + if (matrix[i] < 0) + { + array[t] = matrix[i]; + t++; + } + } + int k = 1; + while (k < count) + { + if (k == 0 || array[k] < array[k - 1]) + { + k++; + } + else + { + (array[k], array[k - 1]) = (array[k - 1], array[k]); + k--; + } + } + int x = 0; + for (int i = 0; i < matrix.Length; i++) + { + if (matrix[i] < 0) + { + matrix[i] = array[x]; + x++; + } + } + } + public void SortRowsByMaxAscending(int[,] matrix) + { + int k = 1, n = matrix.GetLength(0); + while (k < n) + { + if (k != 0) + { + int max2 = GetRowMax(matrix, k); + int max1 = GetRowMax(matrix, k - 1); + if (max1 <= max2) + { + k++; + } + else + { + for (int i = 0; i < matrix.GetLength(1); i++) + { + (matrix[k, i], matrix[k - 1, i]) = (matrix[k - 1, i], matrix[k, i]); + } + k--; + } + } + else k++; + } + } + public void SortRowsByMaxDescending(int[,] matrix) + { + int k = 1, n = matrix.GetLength(0); + while (k < n) + { + if (k != 0) + { + int max2 = GetRowMax(matrix, k); + int max1 = GetRowMax(matrix, k - 1); + if (max1 >= max2) + { + k++; + } + else + { + for (int i = 0; i < matrix.GetLength(1); i++) + { + (matrix[k, i], matrix[k - 1, i]) = (matrix[k - 1, i], matrix[k, i]); + } + k--; + } + } + else k++; + } + } + public int GetRowMax(int[,] matrix, int row) + { + int max = matrix[row,0]; + for (int i = 0; i < matrix.GetLength(1); i++) + { + if (matrix[row,i] > max) + { + max = matrix[row, i]; + } + } + return max; + } + public int[] FindNegativeCountPerRow(int[,] matrix) + { + int[] array = new int[matrix.GetLength(0)]; + for (int i = 0; i < matrix.GetLength(0); i++) + { + int count = 0; + for (int j = 0; j < matrix.GetLength(1); j++) + { + if (matrix[i,j] < 0) + { + count++; + } + } + array[i] = count; + } + return array; + } + public int[] FindMaxNegativePerColumn(int[,] matrix) + { + int[] array = new int[matrix.GetLength(1)]; + for (int j = 0; j < matrix.GetLength(1); j++) + { + int max = -1000000000, count = 0; + for (int i = 0; i < matrix.GetLength(0); i++) + { + if (matrix[i,j] > max && matrix[i,j] < 0) + { + max = matrix[i, j]; + count++; + } + } + if (count > 0) + { + array[j] = max; + } + else array[j] = 0; + } + return array; + } + public int[,] DefineSeq(int[,] matrix) + { + int[,] result = new int[1, 1]; + int f1 = 0, f0 = 0, fMinus1 = 0; + for (int i = 1; i < matrix.GetLength(1); i++) + { + if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] <= matrix[1, i]) + { + f1 = 1; + } + else if ((matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] >= matrix[1, i])) + { + fMinus1 = 1; + } + else + { + f0 = 1; + } + } + int q = matrix[0,0], w = 0; + for (int i = 0; i < matrix.GetLength(1); i++) // проверка на одинаковые значения + { + if (matrix[0,i] != q) + { + w = 1; + } + } + if (w == 1) + { + if (f1 == 1 && fMinus1 == 0 && f0 == 0) + { + result[0, 0] = 1; + } + else if (f1 == 0 && fMinus1 == 1 && f0 == 0) + { + result[0, 0] = -1; + } + else result[0, 0] = 0; + return result; + } + else + { + int[,] a = new int[0, 0];// возвращает пустой массив + return a; + } + } + public int[,] FindAllSeq(int[,] matrix) + { + int count = 0, f1 = 0, fMinus1 = 0; + for (int i = 1; i < matrix.GetLength(1); i++) // находим кол-во интервалов + { + if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] < matrix[1, i] && fMinus1 == 0 && f1 == 0) + { + count++; + f1 = 1; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] > matrix[1, i] && fMinus1 == 0 && f1 == 0) + { + count++; + fMinus1 = 1; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] > matrix[1, i] && f1 == 1) + { + count++; + fMinus1 = 1; + f1 = 0; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] < matrix[1, i] && fMinus1 == 1) + { + count++; + fMinus1 = 0; + f1 = 1; + } + } + f1 = 0; + fMinus1 = 0; + int[,] result = new int[count, 2]; + int t = 0, k = 0; + for (int i = 1; i < matrix.GetLength(1); i++) + { + if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] <= matrix[1, i] && fMinus1 == 0 && f1 == 0) //возр. + { + result[t, 0] = matrix[0, k]; + f1 = 1; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] >= matrix[1, i] && fMinus1 == 0 && f1 == 0) //убыв. + { + result[t, 0] = matrix[0, k]; + fMinus1 = 1; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] > matrix[1, i] && f1 == 1)//убыв. + { + result[t, 1] = matrix[0, k]; + t++; + result[t, 0] = matrix[0, k]; + fMinus1 = 1; + f1 = 0; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] < matrix[1, i] && fMinus1 == 1)//возр. + { + result[t, 1] = matrix[0, k]; + t++; + result[t, 0] = matrix[0, k]; + fMinus1 = 0; + f1 = 1; + } + k++; + } + if (count > 0) + { + result[count - 1, 1] = matrix[0, matrix.GetLength(1) - 1]; + } + int k1 = 1, n = result.GetLength(0); + while (k1 < n) + { + if (k1 == 0 || result[k1 - 1, 0] <= result[k1, 0]) + { + k1++; + } + else + { + (result[k1 - 1, 0], result[k1, 0]) = (result[k1, 0], result[k1 - 1, 0]); + (result[k1 - 1, 1], result[k1, 1]) = (result[k1, 1], result[k1 - 1, 1]); + k1--; + } + } + int k2 = 1; + while (k2 < n) + { + if (k2 == 0 || result[k2 - 1, 1] <= result[k2, 1]) + { + k2++; + } + else + { + (result[k2 - 1, 0], result[k2, 0]) = (result[k2, 0], result[k2 - 1, 0]); + (result[k2 - 1, 1], result[k2, 1]) = (result[k2, 1], result[k2 - 1, 1]); + k2--; + } + } + if (count == 0) + { + int[,] a = new int[0, 0]; + return a; + } + else return result; + + } + public int[,] FindLongestSeq(int[,] matrix) + { + int count = 0, f1 = 0, fMinus1 = 0; + for (int i = 1; i < matrix.GetLength(1); i++) // находим кол-во интервалов + { + if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] < matrix[1, i] && fMinus1 == 0 && f1 == 0) + { + count++; + f1 = 1; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] > matrix[1, i] && fMinus1 == 0 && f1 == 0) + { + count++; + fMinus1 = 1; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] > matrix[1, i] && f1 == 1) + { + count++; + fMinus1 = 1; + f1 = 0; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] < matrix[1, i] && fMinus1 == 1) + { + count++; + fMinus1 = 0; + f1 = 1; + } + } + f1 = 0; + fMinus1 = 0; + int[,] result = new int[count, 2]; + int t = 0, k = 0; + for (int i = 1; i < matrix.GetLength(1); i++) + { + if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] <= matrix[1, i] && fMinus1 == 0 && f1 == 0) //возр. + { + result[t, 0] = matrix[0, k]; + f1 = 1; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] >= matrix[1, i] && fMinus1 == 0 && f1 == 0) //убыв. + { + result[t, 0] = matrix[0, k]; + fMinus1 = 1; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] > matrix[1, i] && f1 == 1)//убыв. + { + result[t, 1] = matrix[0, k]; + t++; + result[t, 0] = matrix[0, k]; + fMinus1 = 1; + f1 = 0; + } + else if (matrix[0, i - 1] < matrix[0, i] && matrix[1, i - 1] < matrix[1, i] && fMinus1 == 1)//возр. + { + result[t, 1] = matrix[0, k]; + t++; + result[t, 0] = matrix[0, k]; + fMinus1 = 0; + f1 = 1; + } + k++; + } + if (count > 0) + { + result[count - 1, 1] = matrix[0, matrix.GetLength(1) - 1]; + } // result - заполненная таблица координат интервалов + int max = 0, maxPosition = 0; + for (int i = 0; i < result.GetLength(0); i++) + { + if ((result[i,1] - result[i,0]) > max) + { + max = result[i, 1] - result[i, 0]; + maxPosition = i; + } + } + if (count == 0) + { + int[,] a = new int[0, 0]; + return a; + } + else + { + int[,] a = new int[1, 2]; + a[0, 0] = result[maxPosition, 0]; + a[0, 1] = result[maxPosition, 1]; + return a; + } + } + public int CountSignFlips(double a, double b, double h, Func func) + { + int count = 0, f1 = 0, fMinus1 = 0; + for (double x = a; x < b; x += h) + { + double y = func(x); + if (y > 0 && f1 == 0 && fMinus1 == 0) + { + f1 = 1; + } + else if (y < 0 && f1 == 0 && fMinus1 == 0) + { + fMinus1 = 1; + } + else if (y > 0 && fMinus1 == 1) + { + count++; + f1 = 1; + fMinus1 = 0; + } + else if (y < 0 && f1 == 1) + { + count++; + f1 = 0; + fMinus1 = 1; + } + } + return count; + } + public double FuncA(double x) + { + double y = x * x - Math.Sin(x); + return y; + } + public double FuncB(double x) + { + double y = Math.Pow(Math.E, x) - 1; + return y; + } + public void SortInCheckersOrder(int[][] array) + { + for (int i = 0; i < array.Length; i++) + { + if (i % 2 == 0) + { + int k = 1, n = array[i].Length; + while (k < n) + { + if ( k == 0 || array[i][k-1] <= array[i][k]) + { + k++; + } + else + { + (array[i][k - 1], array[i][k]) = (array[i][k], array[i][k - 1]); + k--; + } + } + } + else + { + int k = 1, n = array[i].Length; + while (k < n) + { + if (k == 0 || array[i][k - 1] >= array[i][k]) + { + k++; + } + else + { + (array[i][k - 1], array[i][k]) = (array[i][k], array[i][k - 1]); + k--; + } + } + } + } + } + public void SortBySumDesc(int[][] array) + { + int k = 1, n = array.Length; + while (k < n) + { + int sum1 = 0, sum2 = 0; + if (k > 0) + { + for (int j1 = 0; j1 < array[k - 1].Length; j1++) + { + sum1 += array[k - 1][j1]; + } + for (int j2 = 0; j2 < array[k].Length; j2++) + { + sum2 += array[k][j2]; + } + } + if (k == 0 || sum1 >= sum2) + { + k++; + } + else + { + int[] a1 = new int[array[k - 1].Length]; + int[] a2 = new int[array[k].Length]; + for (int i = 0; i < array[k-1].Length; i++) + { + a1[i] = array[k - 1][i]; + } + for (int i = 0; i < array[k].Length; i++) + { + a2[i] = array[k][i]; + } + array[k - 1] = a2; + array[k] = a1; + k--; + } + } + } + public void TotalReverse(int[][] array) + { + for (int i = 0; i < array.Length; i++) + { + for (int j = 0; j < array[i].Length/2; j++) + { + (array[i][j], array[i][^(j + 1)]) = (array[i][^(j + 1)], array[i][j]); + } + } + for (int i = 0; i < array.Length/2; i++) + { + (array[i], array[^(i + 1)]) = (array[^(i + 1)], array[i]); + } + } + public delegate void Sorting(int[] array); + public delegate void SortRowsByMax(int[,] array); + public delegate int[] FindNegatives(int[,] matrix); + public delegate int[,] MathInfo(int[,] matrix); + public delegate double Func(double a); + public delegate int[][] Action(int[][] array); } -} \ No newline at end of file +} diff --git a/Lab6test/BlueTest.cs b/Lab6test/BlueTest.cs index 026ae8da..a255a66f 100644 --- a/Lab6test/BlueTest.cs +++ b/Lab6test/BlueTest.cs @@ -2,1198 +2,5 @@ namespace Lab6test { - [TestClass] - public sealed class BlueTest - { - Lab6.Blue _main = new Lab6.Blue(); - const double E = 0.0001; - Data _data = new Data(); - - [TestMethod] - public void Test01() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {0, -2, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task1(ref input[i]); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test02() - { - // Arrange - var inputA = _data.GetMatrixes(); - var inputB = _data.GetMatrixes(); - var inputC = _data.GetMatrixes(); - Array.Copy(inputA, 0, inputB, 1, 9); - Array.Reverse(inputC); - Array.Copy(inputC, 0, inputB, 1, 3); - var answer = new int[] { 0, 0, -1, -1, 0, 0, 1, 0, 0, 1 }; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task2(inputA[i], inputB[i], inputC[i]); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test03a() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4}, - {5, -6, 7}, - {-1, 4, -5}, - {1, 4, 5}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2}, - {5, 11}, - {0, -2}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, -5}, - {5, 11, -17, 7}, - {-9, -10, -11, -15}, - {-9, -10, -11, -6}, - {0, -2, -3, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task3(ref input[i], _main.FindUpperColIndex); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test03b() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4}, - {5, -6, 7}, - {-1, 4, -5}, - {1, 4, 5}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 3}, - {5, -17}, - {0, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 3, 4, -5}, - {5, -17, 11, 7}, - {-9, -11, -14, -15}, - {-9, -11, -14, -6}, - {0, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task3(ref input[i], _main.FindLowerColIndex); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test04() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1}, - {5}, - {9}, - {13}, - {0}, - }, - new int[,] { - {}, - {}, - {}, - {}, - }, - new int[,] { - {1}, - {5}, - {0}, - }, - new int[,] { - {}, - {}, - {}, - {}, - }, - new int[,] { - {}, - {}, - {}, - {}, - }, - new int[,] { - {1}, - {5}, - {0}, - }, - new int[,] { - {}, - }, - new int[,] { - {}, - {}, - {}, - {}, - {}, - }, - new int[,] { - {1, -6, -7}, - {5, 6, 5}, - {-9, -16, 1}, - {-9, -6, -2}, - {-9, 6, 4}, - {5, 6, -5}, - {1, 0, 0}, - {0, 0, 5}, - }, - new int[,] { - {1}, - {5}, - {-9}, - {-9}, - {0}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task4(ref input[i]); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test05A() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - }, - new int[,] { - {1, 2, 3}, - {0, -2, -3}, - }, - new int[,] { - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task5(ref input[i], _main.FindMax); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test05B() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - }, - new int[,] { - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - }, - new int[,] { - {1, 2, 4, 6}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - }, - new int[,] { - {1, 2, 3}, - {0, -2, -3}, - }, - new int[,] { - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task5(ref input[i], _main.FindMin); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test06A() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-19, -14, -13, 15, 16, 17, 18}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {-15, -14, -11, -10, -9, 6}, - }, - new int[,] { - {-7, -6, -5, 1, 2, 3, 4}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-15, -14, -11, -10, -9, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {-7, -6, -5, 1, 2, 3, 4}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-14, -11, -10, -9, -6, -2, 15}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {-4, -2, 0, 0, 1, 1, 3}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {-5, 1, 2, 3, 4}, - {5, 11, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-14, -11, -10, -9, -6}, - {0, -2, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task6(input[i], _main.SortRowAscending); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - - [TestMethod] - public void Test06B() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {7, 6, 5, 4, 3, 2, 1}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {19, 18, 17, 16, 15, 14, 13}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {6, 5, 4, 3, 2, 1}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {6, 4, 2, 1}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {6, 5, 4, 1}, - }, - new int[,] { - {7, 6, 5, 4, 3, 2, 1}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {18, 17, 16, 15, -13, -14, -19}, - }, - new int[,] { - {3, 2, 1}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {6, -9, -10, -11, -14, -15}, - }, - new int[,] { - {4, 3, 2, 1, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-2, -6, -9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {4, 3, 2, 1, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {15, -2, -6, -9, -10, -11, -14}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {3, 1, 1, 0, 0, -2, -4}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {4, 3, 2, 1, -5}, - {5, 11, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-6, -9, -10, -11, -14}, - {0, -2, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task6(input[i], _main.SortRowDescending); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test07A() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 0}, - {5, 6, 7, 8, 9, 10, 0}, - {9, 10, 11, 12, 13, 14, 0}, - {13, 14, 15, 16, 17, 18, 0}, - {0, 1, 2, 3, 4, 5, 0}, - }, - new int[,] { - {0}, - {0}, - {0}, - {0}, - }, - new int[,] { - {1, 2, 3, 4, 5, 0}, - {5, 6, 7, 8, 9, 0}, - {0, 2, 3, 4, 5, 0}, - }, - new int[,] { - {1, 2, 4, 0}, - {5, -6, 7, 0}, - {-1, 4, -5, 0}, - {1, 4, 5, 0}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 0}, - {5, 6, 7, 8, -9, 10, 0}, - {9, 0, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 0, -19}, - }, - new int[,] { - {1, 2, 0}, - {5, 0, -17}, - {0, -2, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 0}, - }, - new int[,] { - {1, 2, 3, 0, -5, -6, -7}, - {5, 0, -17, 0, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 0}, - {-9, -10, -11, -14, -15, -6, 0}, - {-9, -10, -11, -14, -15, 0, 4}, - }, - new int[,] { - {1, 2, 3, 0, -5, -6, -7}, - {5, 0, -17, 0, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 0}, - {-9, -10, -11, -14, 0, -6, -2}, - {-9, -10, -11, -14, -15, 0, 4}, - {5, 0, -17, 0, -10, 6, -5}, - {1, 1, -2, 0, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 0}, - }, - new int[,] { - {1, 2, 3, 0, -5}, - {5, 0, -17, 0, 7}, - {0, -10, -11, -14, -15}, - {-9, -10, -11, -14, 0}, - {0, -2, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task7(input[i], _main.ReplaceByZero); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test07B() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 49}, - {5, 6, 7, 8, 9, 10, 77}, - {9, 10, 11, 12, 13, 14, 105}, - {13, 14, 15, 16, 17, 18, 133}, - {0, 1, 2, 3, 4, 5, 42}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 36}, - {5, 6, 7, 8, 9, 66}, - {0, 2, 3, 4, 5, 36}, - }, - new int[,] { - {1, 2, 4, 24}, - {5, -6, 7, 44}, - {-1, 4, -5, 24}, - {1, 4, 5, 24}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 49}, - {5, 6, 7, 8, -9, 10, 77}, - {9, 20, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 108, -19}, - }, - new int[,] { - {1, 2, 9}, - {5, 22, -17}, - {0, -2, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 36}, - }, - new int[,] { - {1, 2, 3, 16, -5, -6, -7}, - {5, 22, -17, 44, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 7}, - {-9, -10, -11, -14, -15, -6, -14}, - {-9, -10, -11, -14, -15, 36, 4}, - }, - new int[,] { - {1, 2, 3, 16, -5, -6, -7}, - {5, 22, -17, 44, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 7}, - {-9, -10, -11, -14, 75, -6, -2}, - {-9, -10, -11, -14, -15, 36, 4}, - {5, 22, -17, 44, -10, 6, -5}, - {1, 1, -2, 12, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 35}, - }, - new int[,] { - {1, 2, 3, 16, -5}, - {5, 22, -17, 44, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -30}, - {0, -2, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task7(input[i], _main.MultiplyByColumn); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test08A() - { - // Arrange - var inputA = 0.1; - var inputB = 1; - var inputH = 0.1; - var answer = new double[,] { - {2.6912681270017194, 2.691268139166703}, - {2.6122212502032887, 2.6122204929844544}, - {2.4868568953361008, 2.486856868603152}, - {2.323884253225943, 2.3238842457941966}, - {2.1339300133437806, 2.133930111437405}, - {1.9283342127279457, 1.9283342378052784}, - {1.7179999583568928, 1.7179999609519054}, - {1.5124670271786733, 1.5124670047163078}, - {1.3193029843812667, 1.3193027107322826}, - {1.1438356417724056, 1.1438356437916406}, - }; - var test = new double[answer.GetLength(0), answer.GetLength(1)]; - // Act - test = _main.Task8(inputA, inputB, inputH, _main.SumA, _main.YA); - // Assert - Assert.AreEqual(answer.GetLength(0), test.GetLength(0)); - Assert.AreEqual(answer.GetLength(1), test.GetLength(1)); - for (int i = 0; i < answer.GetLength(0); i++) - { - for (int j = 0; j < answer.GetLength(1); j++) - { - Assert.AreEqual(answer[i, j], test[i, j], E); - } - } - } - [TestMethod] - public void Test08B() - { - // Arrange - var inputA = Math.PI / 5; - var inputB = Math.PI; - var inputH = Math.PI / 25; - var answer = new double[,] { - {-7.303507257791954, -7.303507256806125}, - {-7.260083616438886, -7.260080997441332}, - {-7.20875508832593, -7.208759054555667}, - {-7.149545913780194, -7.149541428149131}, - {-7.082422850960618, -7.082428118221723}, - {-7.007419743934666, -7.0074191247734445}, - {-6.924507777616338, -6.9245144478042935}, - {-6.833707144188682, -6.833714087314272}, - {-6.735009114927305, -6.735018043303378}, - {-6.628434910121376, -6.6284263157716135}, - {-6.51393629032441, -6.513938904718977}, - {-6.391544374889424, -6.391555810145468}, - {-6.261289902367042, -6.261277032051089}, - {-6.123087221829428, -6.1231025704358375}, - {-5.977012101846995, -5.977032425299715}, - {-5.823071802317092, -5.823066596642721}, - {-5.661174273430562, -5.661205084464855}, - {-5.49140693658761, -5.491447888766118}, - {-5.313734462977021, -5.313795009546508}, - {-5.128131509726421, -5.128246446806029}, - {-4.935801700711345, -4.934802200544677}, - }; - var test = new double[answer.GetLength(0), answer.GetLength(1)]; - // Act - test = _main.Task8(inputA, inputB, inputH, _main.SumB, _main.YB); - // Assert - Assert.AreEqual(answer.GetLength(0), test.GetLength(0)); - Assert.AreEqual(answer.GetLength(1), test.GetLength(1)); - for (int i = 0; i < answer.GetLength(0); i++) - { - for (int j = 0; j < answer.GetLength(1); j++) - { - Assert.AreEqual(answer[i, j], test[i, j], E); - } - } - } - [TestMethod] - public void Test09A() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[] { 0, 0, 0, 360, 0, 433, 0, 0, 0, 1434 }; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task9(input[i], _main.GetUpperTriangle); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test09B() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[] { 0, 0, 0, 182, 0, 160, 0, 0, 0, 1001 }; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task9(input[i], _main.GetLowerTriangle); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test10A() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new bool[5] { false, true, true, true, false }; - var test = new bool[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.CheckTransformAbility); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test10B() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new bool[5] { false, false, true, false, false }; - var test = new bool[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.CheckSumOrder); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test10C() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new bool[5] { true, true, false, true, false }; - var test = new bool[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.CheckArraysOrder); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test_FindDiagonalMaxIndex() - { - var matrix = new int[,] { { 1, 2 }, { 3, 4 } }; - int result = _main.FindDiagonalMaxIndex(matrix); - Assert.AreEqual(1, result); - } - - [TestMethod] - public void Test_RemoveRow() - { - var matrix = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 } }; - _main.RemoveRow(ref matrix, 1); - var expected = new int[,] { { 1, 2 }, { 5, 6 } }; - CollectionAssert.AreEqual(expected.Cast().ToArray(), matrix.Cast().ToArray()); - } - - [TestMethod] - public void Test_GetAverageExceptEdges() - { - var matrix = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }; - double avg = _main.GetAverageExceptEdges(matrix); - // Убираем 1 и 6 → остаются [2,3,4,5], среднее = 3.5 - Assert.AreEqual(3.5, avg, E); - } - - [TestMethod] - public void Test_FindMaxMin() - { - var matrix = new int[,] { { -2, 10 }, { 5, 0 } }; - Assert.AreEqual(10, _main.FindMax(matrix)); - Assert.AreEqual(-2, _main.FindMin(matrix)); - } - - [TestMethod] - public void Test_RemoveColumn() - { - var matrix = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } }; - _main.RemoveColumn(ref matrix, 1); - var expected = new int[,] { { 1, 3 }, { 4, 6 } }; - CollectionAssert.AreEqual(expected.Cast().ToArray(), matrix.Cast().ToArray()); - } - - [TestMethod] - public void Test_CheckZerosInColumn() - { - var matrix = new int[,] { { 1, 0 }, { 3, 4 } }; - Assert.IsTrue(_main.CheckZerosInColumn(matrix, 1)); - Assert.IsFalse(_main.CheckZerosInColumn(matrix, 0)); - } - - [TestMethod] - public void Test_FindMaxMinWithOut() - { - var matrix = new int[,] { { 1, 2 }, { 3, 4 } }; - int row, col; - Assert.AreEqual(4, _main.FindMax(matrix, out row, out col)); - Assert.AreEqual(1, _main.FindMin(matrix, out row, out col)); - } - - [TestMethod] - public void Test_SortRowAscendingDescending() - { - var matrix = new int[,] { { 3, 1, 2 }, - { 8, 2, 54 } }; - _main.SortRowAscending(matrix, 0); - CollectionAssert.AreEqual(new int[] { 1, 2, 3, 8, 2, 54 }, matrix.Cast().ToArray()); - - matrix = new int[,] { { 3, 1, 2 }, - { 8, 2, 54 } }; - _main.SortRowDescending(matrix, 0); - CollectionAssert.AreEqual(new int[] { 3, 2, 1, 8, 2, 54 }, matrix.Cast().ToArray()); - } - - [TestMethod] - public void Test_FindMaxInRowAndReplace() - { - var matrix = new int[,] { { 1, 3, 3 } }; - int max = _main.FindMaxInRow(matrix, 0); - Assert.AreEqual(3, max); - - _main.ReplaceByZero(matrix, 0, max); - CollectionAssert.AreEqual(new int[] { 1, 0, 0 }, matrix.Cast().ToArray()); - } - - [TestMethod] - public void Test_MultiplyByColumn() - { - var matrix = new int[,] { { 2, 5, 5 } }; - _main.MultiplyByColumn(matrix, 0, 5); - // 5*2 и 5*3 → 10, 15 - CollectionAssert.AreEqual(new int[] { 2, 10, 15 }, matrix.Cast().ToArray()); - } - - [TestMethod] - public void Test_Sum_Simple() - { - var arr = new int[] { 1, 2, 3 }; - int result = _main.Sum(arr); - // 1²+2²+3²=14 - Assert.AreEqual(14, result); - } - - [TestMethod] - public void Test_GetUpperAndLowerTriangle() - { - var matrix = new int[,] { { 1, 2 }, { 3, 4 } }; - var upper = _main.GetUpperTriangle(matrix); - var lower = _main.GetLowerTriangle(matrix); - CollectionAssert.AreEqual(new int[] { 1, 2, 4 }, upper); - CollectionAssert.AreEqual(new int[] { 1, 3, 4 }, lower); - } - - [TestMethod] - public void Test_CheckSumOrder() - { - var array = new int[][] { new[] { 1, 2 }, new[] { 3, 4 }, new[] { 5, 6 } }; - Assert.IsTrue(_main.CheckSumOrder(array)); // возрастающая сумма - } - - [TestMethod] - public void Test_CheckArraysOrder() - { - var array = new int[][] { new[] { 1, 2, 3 }, new[] { 3, 1 } }; - Assert.IsTrue(_main.CheckArraysOrder(array)); // один из массивов упорядочен - } - - [TestMethod] - public void Test_CheckTransformAbility() - { - var array = new int[][] { new[] { 1, 2, 3 }, new[] { 4, 5 }, new[] { 6 } }; - Assert.IsTrue(_main.CheckTransformAbility(array)); - } - } } + diff --git a/Lab6test/GreenTest.cs b/Lab6test/GreenTest.cs index a219a3ca..a255a66f 100644 --- a/Lab6test/GreenTest.cs +++ b/Lab6test/GreenTest.cs @@ -2,1027 +2,5 @@ namespace Lab6test { - [TestClass] - public sealed class GreenTest - { - Lab6.Green _main = new Lab6.Green(); - const double E = 0.0001; - Data _data = new Data(); - - [TestMethod] - public void Test01() - { - // Arrange - var inputA = new int[][] { - new int[] { -2, -1, -3, -4 }, - new int[] { 2, 1, 3, 4 }, - new int[] { 0, 2, 4, 6, 8 }, - new int[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new int[] { 5, 2, -8, 1, 9, 3, 7, 4, 6 }, - new int[] { 12, 1, 3, 3, 5, 6, 3, 4 }, - new int[] { -2, -1, -3, -4 }, - new int[] { 0, 2, 4, 6, 8 }, - new int[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new int[] { 5, 2, 8, 1, 9, 0, 7, 4, 6 } - }; - var inputB = new int[][] { - new int[] { 0, 0, 0, 0, 0 }, - new int[] { 5 }, - new int[] { 0, 2, 4, 6, 8 }, - new int[] { 5, 2, -8, 1, 9, 3, 7, 4, 6 }, - new int[] { 5, 2, 8, 1, 4, 3, 7, 4, 6, 0 }, - new int[] { 0, 0, 0, 0, 0 }, - new int[] { 5 }, - new int[] { 0, 2, 4, 6, 8 }, - new int[] { 5, 2, -8, 1, 9, 3, 7, 4, 6 }, - new int[] { 5, 2, 8, 1, 4, 3, 7, 4, 6, 0 } - }; - var answerA = new int[][] { - new int[] { -2, -3, -4, 0, 0, 0, 0 }, - new int[] { 2, 1, 3 }, - new int[] { 0, 2, 4, 6, 0, 2, 4, 6 }, - new int[] { 2, 1, 3, 3, 5, 3, 4, 5, 2, -8, 1, 3, 7, 4, 6 }, - new int[] { 5, 2, -8, 1, 3, 7, 4, 6, 5, 2, 1, 4, 3, 7, 4, 6, 0 }, - new int[] { 1, 3, 3, 5, 6, 3, 4, 0, 0, 0, 0 }, - new int[] { -2, -3, -4 }, - new int[] { 0, 2, 4, 6, 0, 2, 4, 6 }, - new int[] { 2, 1, 3, 3, 5, 3, 4, 5, 2, -8, 1, 3, 7, 4, 6 }, - new int[] { 5, 2, 8, 1, 0, 7, 4, 6, 5, 2, 1, 4, 3, 7, 4, 6, 0 } - }; - var answerB = new int[][] { - new int[] { 0, 0, 0, 0 }, - new int[] { }, - new int[] { 0, 2, 4, 6 }, - new int[] { 5, 2, -8, 1, 3, 7, 4, 6 }, - new int[] { 5, 2, 1, 4, 3, 7, 4, 6, 0 }, - new int[] { 0, 0, 0, 0 }, - new int[] { }, - new int[] { 0, 2, 4, 6 }, - new int[] { 5, 2, -8, 1, 3, 7, 4, 6 }, - new int[] { 5, 2, 1, 4, 3, 7, 4, 6, 0 } - }; - // Act - for (int i = 0; i < answerA.Length; i++) - { - _main.Task1(ref inputA[i], ref inputB[i]); - } - // Assert - for (int i = 0; i < answerA.Length; i++) - { - Assert.AreEqual(answerA[i].Length, inputA[i].Length); - for (int j = 0; j < answerA[i].Length; j++) - { - Assert.AreEqual(answerA[i][j], inputA[i][j], E); - } - Assert.AreEqual(answerB[i].Length, inputB[i].Length); - for (int j = 0; j < answerB[i].Length; j++) - { - Assert.AreEqual(answerB[i][j], inputB[i][j], E); - } - } - } - [TestMethod] - public void Test02() - { - // Arrange - var inputA = _data.GetMatrixes(); - var inputB = new int[][] { - new int[] { -2, -1, -3, -4 }, - new int[] { 2, 1, 3, 4 }, - new int[] { 0, 2, 4, 6, 8, -2 }, - new int[] { 3, 3, 3, 3 }, - new int[] { 5, 2, -8, 1, 9, 4, 6 }, - new int[] { 12, 1, 3, 3, 5, 6, 3, 4 }, - new int[] { -2, -1, -3 }, - new int[] { 0, 2, 4, 6, 8, 11, 25 }, - new int[] { 2, 1, 3, 3, 5, 6, 3 }, - new int[] { 50, 20, 8, 1, 9 } - }; - var answerA = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {2}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 50, -5}, - {5, 20, -17, 11, 7}, - {8, -10, -11, -14, -15}, - {-9, -10, -11, -14, 1}, - {9, -2, -3, -4, -5}, - } - }; - var answerB = new int[][] { - new int[] { -2, -1, -3, -4 }, - new int[] { 2, 1, 3, 4 }, - new int[] { 0, 2, 4, 6, 8, -2 }, - new int[] { 3, 3, 3, 3 }, - new int[] { 5, 2, -8, 1, 9, 4, 6 }, - new int[] { 12, 1, 3, 3, 5, 6, 3, 4 }, - new int[] { -2, -1, -3 }, - new int[] { 0, 2, 4, 6, 8, 11, 25 }, - new int[] { 2, 1, 3, 3, 5, 6, 3 }, - new int[] { 50, 20, 8, 1, 9 } - }; - // Act - for (int i = 0; i < inputA.Length; i++) - { - _main.Task2(inputA[i], inputB[i]); - } - // Assert - for (int i = 0; i < inputA.Length; i++) - { - Assert.AreEqual(answerA[i].GetLength(0), inputA[i].GetLength(0)); - for (int j = 0; j < inputA[i].GetLength(0); j++) - { - Assert.AreEqual(answerA[i].GetLength(1), inputA[i].GetLength(1)); - for (int k = 0; k < inputA[i].GetLength(1); k++) - { - Assert.AreEqual(answerA[i][j, k], inputA[i][j, k]); - } - } - Assert.AreEqual(answerB[i].Length, inputB[i].Length); - for (int j = 0; j < answerB[i].Length; j++) - { - Assert.AreEqual(answerB[i][j], inputB[i][j], E); - } - } - } - [TestMethod] - public void Test03() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {6, 2, 4, 1}, - {5, 11, 7, -6}, - {-1, 4, 6, -5}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {2, 1, 3}, - {5, 11, -17}, - {0, -3, -2}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {2, 1, 3, 4, -5}, - {5, 11, -17, 11, 7}, - {-9, -11, -10, -14, -15}, - {-9, -14, -11, -10, -6}, - {0, -5, -3, -4, -2}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task3(input[i]); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test04() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {5, 11, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task4(ref input[i]); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test05() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][] { - null, - null, - null, - new int[] { 1, -6, -5, 6 }, - null, - new int[] { 1, -17, -3 }, - null, - null, - null, - new int[] { -5, -17, -15, -14, -5 } - }; - var test = new int[answer.Length][]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task5(input[i]); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - if (answer[i] == null) - { - Assert.IsNull(test[i]); - continue; - } - Assert.AreEqual(answer[i].Length, test[i].Length); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i][j], test[i][j]); - } - } - } - [TestMethod] - public void Test06() - { - // Arrange - var inputA = _data.GetMatrixes(); - var inputB = _data.GetMatrixes(); - Array.Reverse(inputB); - var answer = new int[][] { - new int[] { 28, 33, 38, 43, 48, 53, 58, 6, 13, 3, 15, 7 }, - new int[] { 28, 12, 25, 3, 29, 15, 18, 15 }, - new int[] { 6, 10, 13, 16, 19, 23, 6, 13, 3, 15, 0, 12, 10 }, - new int[] { 7, 10, 16, 29, 0, 0, 0, 0, 0, 6 }, - new int[] { 15, 18, 25, 28, 22, 34, 18, 6, 13, 3 }, - new int[] { 6, 13, 3, 15, 18, 25, 28, 22, 34, 18 }, - new int[] { 0, 0, 0, 0, 0, 6, 7, 10, 16, 29 }, - new int[] { 6, 13, 3, 15, 0, 12, 10, 6, 10, 13, 16, 19, 23 }, - new int[] { 12, 25, 3, 29, 15, 18, 15, 28 }, - new int[] { 6, 13, 3, 15, 7, 28, 33, 38, 43, 48, 53, 58 } - }; - var test = new int[answer.Length][]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task6(inputA[i], inputB[i]); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].Length, test[i].Length); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i][j], test[i][j]); - } - } - } - [TestMethod] - public void Test07A() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -15, -14, -13, -12, -11}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -3, -2}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -7, -6, -5}, - {5, 11, -17, -10, 5, 6, 11}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -7, -6, -5}, - {5, 11, -17, -10, 5, 6, 11}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, -10, -5, 6, 11}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {5, 11, -17, 7, 11}, - {-9, -15, -14, -11, -10}, - {-9, -10, -11, -14, -6}, - {0, -5, -4, -3, -2}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task7(input[i], _main.SortEndAscending); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test07B() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, 11, 6, 5, -10, -17}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, 11, 6, 5, -10, -17}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -2, -6}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, 11, 6, -5, -10, -17}, - {1, 1, -2, 3, 0, 0, -4}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {5, 11, 11, 7, -17}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task7(input[i], _main.SortEndDescending); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test08() - { - // Arrange - var inputA = new double[][] { - new double[] { 2, 1.5, 3 }, - new double[] { 1.9, 3, 4 }, - new double[] { 4, 6, 8 }, - new double[] { 2, 3, 3 }, - new double[] { 5, 6, 8 }, - new double[] { 12, 13, 35 }, - new double[] { 13, 14, 15 }, - new double[] { 12, 12, 12 }, - new double[] { 15, 15, 15 }, - new double[] { 5, 10, 8 } - }; - var inputB = new double[][] { - new double[] { 5, 6, 8 }, - new double[] { 1.7, 3, 4 }, - new double[] { 2, 1.5, 3 }, - new double[] { 12, 13, 35 }, - new double[] { 13, 14, 15 }, - new double[] { 15, 15, 15 }, - new double[] { 4, 6, 8 }, - new double[] { 12, 12, 12 }, - new double[] { 2, 3, 3 }, - new double[] { 5, 10, 8 } - }; - var answer = new int[10] { 2, 1, 1, 1, 2, 2, 1, 2, 1, 2}; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task8(inputA[i], inputB[i]); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i], E); - } - } - [TestMethod] - public void Test09B() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {7, 6, 5, 4, 3, 2, 1}, - {5, 6, 7, 8, 9, 10, 11}, - {15, 14, 13, 12, 11, 10, 9}, - {13, 14, 15, 16, 17, 18, 19}, - {6, 5, 4, 3, 2, 1, 0}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {6, 5, 4, 3, 2, 1}, - {5, 6, 7, 8, 9, 11}, - {6, 5, 4, 3, 2, 0}, - }, - new int[,] { - {6, 4, 2, 1}, - {5, -6, 7, 11}, - {6, 4, -1, -5}, - {1, 4, 5, 6}, - }, - new int[,] { - {7, 6, 5, 4, 3, 2, 1}, - {5, 6, 7, 8, -9, 10, 11}, - {10, 9, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {3, 2, 1}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {6, -9, -10, -11, -14, -15}, - }, - new int[,] { - {4, 3, 2, 1, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {1, -9, -10, -11, -14, -15, -16}, - {-9, -10, -11, -14, -15, -6, -2}, - {6, 4, -9, -10, -11, -14, -15}, - }, - new int[,] { - {4, 3, 2, 1, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {1, -9, -10, -11, -14, -15, -16}, - {-9, -10, -11, -14, 15, -6, -2}, - {6, 4, -9, -10, -11, -14, -15}, - {5, 11, -17, 11, -10, 6, -5}, - {3, 1, 1, 0, 0, -2, -4}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {4, 3, 2, 1, -5}, - {5, 11, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - }, - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task9(input[i], _main.SortDescending); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test09A() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-5, -1, 4, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {-15, -14, -13, -12, -11, 9, 10}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {-3, -2, 0}, - }, - new int[,] { - {-15, -14, -11, -10, -9, 6}, - }, - new int[,] { - {-7, -6, -5, 1, 2, 3, 4}, - {5, 11, -17, 11, -10, 6, 5}, - {-16, -15, -14, -11, -10, -9, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-15, -14, -11, -10, -9, 4, 6}, - }, - new int[,] { - {-7, -6, -5, 1, 2, 3, 4}, - {5, 11, -17, 11, -10, 6, 5}, - {-16, -15, -14, -11, -10, -9, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-15, -14, -11, -10, -9, 4, 6}, - {5, 11, -17, 11, -10, 6, -5}, - {-4, -2, 0, 0, 1, 1, 3}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {-5, 1, 2, 3, 4}, - {5, 11, -17, 11, 7}, - {-15, -14, -11, -10, -9}, - {-9, -10, -11, -14, -6}, - {-5, -4, -3, -2, 0}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task9(input[i], _main.SortAscending); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test10A() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new double[5] { 1, 1, 0, 1, 0 }; - var test = new double[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.CountZeroSum); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i], E); - } - } - [TestMethod] - public void Test10B() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new double[5] { 3, 2, 3, 1, 3 }; - var test = new double[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.FindMedian); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i], E); - } - } - [TestMethod] - public void Test10C() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new double[5] { 32, 20, 5, 0, 26 }; - var test = new double[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.CountLargeElements); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i], E); - } - } - [TestMethod] - public void Test_DeleteMaxElement() - { - int[] array = { 1, 5, 3, 9, 2 }; - int[] expected = { 1, 5, 3, 2 }; - _main.DeleteMaxElement(ref array); - CollectionAssert.AreEqual(expected, array); - } - - [TestMethod] - public void Test_CombineArrays() - { - int[] A = { 1, 2 }; - int[] B = { 3, 4 }; - int[] expected = { 1, 2, 3, 4 }; - int[] actual = _main.CombineArrays(A, B); - CollectionAssert.AreEqual(expected, actual); - } - - [TestMethod] - public void Test_FindMaxInRow() - { - int[,] matrix = { - { 1, 2, -33 }, - { 4, 0, 6 }, - { 17, 8, 9 } - }; - int expected = 6; - int actual = _main.FindMaxInRow(matrix, 1, out int col); - Assert.AreEqual(expected, actual); - Assert.AreEqual(col, 2); - } - - [TestMethod] - public void Test_FindMax_Matrix() - { - int[,] matrix = { - { 1, 2 }, - { 3, 4 } - }; - _main.FindMax(matrix, out int row, out int col); - Assert.AreEqual(1, row); - Assert.AreEqual(1, col); - } - - [TestMethod] - public void Test_SwapColWithDiagonal() - { - int[,] matrix = { - { 1, 2, 7 }, - { 3, 4, 3 }, - { 0, 8, 2 } - }; - _main.SwapColWithDiagonal(matrix, 1); - int[,] expected = { - { 2, 1, 7 }, - { 3, 4, 3 }, - { 0, 2, 8 } - }; // здесь пример, где результат совпадает с исходным (для 2x2) - CollectionAssert.AreEqual(expected.Cast().ToArray(), matrix.Cast().ToArray()); - } - - [TestMethod] - public void Test_RemoveRow() - { - int[,] matrix = { - { 1, 0 }, - { 2, 3 } - }; - _main.RemoveRow(ref matrix, 0); - int[,] expected = { { 2, 3 } }; - CollectionAssert.AreEqual(expected.Cast().ToArray(), matrix.Cast().ToArray()); - } - - [TestMethod] - public void Test_GetRowsMinElements() - { - int[,] matrix = { - { 1, 2, 3 }, - { 4, 0, 6 }, - { 7, 8, 9 } - }; - int[] expected = { 1, 0, 9 }; - int[] actual = _main.GetRowsMinElements(matrix); - CollectionAssert.AreEqual(expected, actual); - } - - [TestMethod] - public void Test_SumPositiveElementsInColumns() - { - int[,] matrix = { - { 1, -2 }, - { 3, 4 } - }; - int[] expected = { 4, 4 }; - int[] actual = _main.SumPositiveElementsInColumns(matrix); - CollectionAssert.AreEqual(expected, actual); - } - - [TestMethod] - public void Test_GeronArea() - { - double area = _main.GeronArea(3, 4, 5); - Assert.AreEqual(6, area, 0.0001); - } - [TestMethod] - public void Test_CountZeroSum() - { - int[][] array = { - new[] { 1, -1, 0 }, - new[] { 2, 2, 2 } - }; - Assert.AreEqual(1, _main.CountZeroSum(array), E); - } - [TestMethod] - public void Test_FindMedian() - { - int[][] array = { - new[] { 1, -1, 0 }, - new[] { 2, 2, 2 } - }; - Assert.AreEqual(1.5, _main.FindMedian(array), E); // median: -1,0,1,2,2,2 => 1.5 - } - [TestMethod] - public void Test_CountLargeElements() - { - int[][] array = { - new[] { 1, -1, 0 }, - new[] { 2, 2, 2 } - }; - Assert.AreEqual(1, _main.CountLargeElements(array), E); - } - } } + diff --git a/Lab6test/WhiteTest.cs b/Lab6test/WhiteTest.cs index afb9acbc..a255a66f 100644 --- a/Lab6test/WhiteTest.cs +++ b/Lab6test/WhiteTest.cs @@ -1,1280 +1,6 @@ -using Lab6; -using Microsoft.ApplicationInsights; -using System.Transactions; +using System.Transactions; namespace Lab6test { - [TestClass] - public sealed class WhiteTest - { - Lab6.White _main = new Lab6.White(); - const double E = 0.0001; - Data _data = new Data(); - - [TestMethod] - public void Test01() - { - // Arrange - var inputA = new double[][] { - new double[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 12, 1, 3, 3, 5, 6, 13, 4 }, - new double[] { 5, 2, 8, 1, 9, 3, 7, 4, 6, 0 }, - new double[] { -2, -1, -3, -4 }, - new double[] { 0, 2, 4, 6, 8 }, - new double[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 5, 2, -8, 1, 9, 3, 7, 4, 6 }, - new double[] { 12, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 5, 2, 8, 1, 9, 3, 7, 4, 6, 0 }, - new double[] { 5, 2, 8, 1, 9, 0, 7, 4, 6, 10 } - }; - var inputB = new double[][] { - new double[] { -2, -1, -3, -4 }, - new double[] { 2, 1, 3, 0 }, - new double[] { 0, 2, 4, 6, 8 }, - new double[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 5, 2, -8, 1, 9, 3, 7, 4, 6 }, - new double[] { 12, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { -2, -1, -3, -4 }, - new double[] { 0, 2, 4, 6, 8 }, - new double[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 5, 2, 8, 1, 9, 0, 7, 4, 6 } - }; - var answerA = new double[][] { - new double[] { 2, 1, 3, 3, 5, 3.5, 3, 4 }, - new double[] { 12, 1, 3, 3, 5, 6, 4, 4 }, - new double[] { 5, 2, 8, 1, 4, 3, 7, 4, 6, 0 }, - new double[] { -2, -3.5, -3, -4 }, - new double[] { 0, 2, 4, 6, 8 }, - new double[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 5, 2, -8, 1, 5, 3, 7, 4, 6 }, - new double[] { 3.5714285714285716, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 5, 2, 8, 1, 4, 3, 7, 4, 6, 0 }, - new double[] { 5, 2, 8, 1, 9, 0, 7, 4, 6, 10 } - }; - var answerB = new double[][] { - new double[] { -2, -1, -3, -4 }, - new double[] { 2, 1, 3, 0 }, - new double[] { 0, 2, 4, 6, 8 }, - new double[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 5, 2, -8, 1, 5, 3, 7, 4, 6 }, - new double[] { 3.5714285714285716, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { -2, -1, -3, -4 }, - new double[] { 0, 2, 4, 6, 8 }, - new double[] { 2, 1, 3, 3, 5, 6, 3, 4 }, - new double[] { 5, 2, 8, 1, 4.25, 0, 7, 4, 6 } - }; - // Act - for (int i = 0; i < answerA.Length; i++) - { - _main.Task1(inputA[i], inputB[i]); - } - // Assert - for (int i = 0; i < answerA.Length; i++) - { - Assert.AreEqual(answerA[i].Length, inputA[i].Length); - for (int j = 0; j < answerA[i].Length; j++) - { - Assert.AreEqual(answerA[i][j], inputA[i][j], E); - } - Assert.AreEqual(answerB[i].Length, inputB[i].Length); - for (int j = 0; j < answerB[i].Length; j++) - { - Assert.AreEqual(answerB[i][j], inputB[i][j], E); - } - } - } - [TestMethod] - public void Test02() - { - // Arrange - var inputA = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - {9, 10, 11, 12, 13, 14}, - {13, 14, 15, 16, 17, 19}, - {0, 1, 2, 3, 4, 5}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {5, 11, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {5, 6, 7, 8, 9, 10, 11}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {5, 6, 7, 8, 9, 10, 11}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - {9, 10, 11, 12, 13, 14}, - {13, 14, 15, 16, 17, 19}, - {0, 1, 2, 3, 4, 5}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {0, -2, -3, -4, -5, 0, 5}, - } - }; - var inputB = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - {9, 10, 11, 12, 13, 14}, - {13, 14, 15, 16, 17, 19}, - {0, 1, 2, 3, 4, 5}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {5, 11, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {5, 6, 7, 8, 9, 10, 11}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {5, 6, 7, 8, 9, 10, 11}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - {9, 10, 11, 12, 13, 14}, - {13, 14, 15, 16, 17, 19}, - {0, 1, 2, 3, 4, 5}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {0, -2, -3, -4, -5, 0, 5}, - } - }; - Array.Reverse(inputB); - var answerA = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {5, 11, -17, 11, -10, 6, 5}, - {0, 1, 2, 3, 4, 5, 6}, - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - {9, 10, 11, 12, 13, 14}, - {13, 14, 15, 16, 17, 19}, - {0, 1, 2, 3, 4, 5}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {5, 11, -17, 11, -10, 6, 5}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {5, 11, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {13, 14, 15, 16, 17, 18, 19}, - {5, 6, 7, 8, 9, 10, 11}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {5, 6, 7, 8, 9, 10, 11}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - {9, 10, 11, 12, 13, 14}, - {13, 14, 15, 16, 17, 19}, - {0, 1, 2, 3, 4, 5}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {13, 14, 15, 16, 17, 18, 19}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {0, -2, -3, -4, -5, 0, 5}, - } - }; - var answerB = new int[][,] { - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {13, 14, 15, 16, 17, 18, 19}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - {9, 10, 11, 12, 13, 14}, - {13, 14, 15, 16, 17, 19}, - {0, 1, 2, 3, 4, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {13, 14, 15, 16, 17, 18, 19}, - {5, 6, 7, 8, 9, 10, 11}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {5, 6, 7, 8, 9, 10, 11}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {5, 11, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {5, 11, -17, 11, -10, 6, 5}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - {9, 10, 11, 12, 13, 14}, - {13, 14, 15, 16, 17, 19}, - {0, 1, 2, 3, 4, 5}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {5, 11, -17, 11, -10, 6, 5}, - {0, 1, 2, 3, 4, 5, 6}, - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - } - }; - // Act - for (int i = 0; i < answerA.Length; i++) - { - _main.Task2(inputA[i], inputB[i]); - } - // Assert - for (int i = 0; i < answerA.Length; i++) - { - Assert.AreEqual(answerA[i].GetLength(0), inputA[i].GetLength(0)); - Assert.AreEqual(answerA[i].GetLength(1), inputA[i].GetLength(1)); - for (int j = 0; j < answerA[i].GetLength(0); j++) - { - for (int k = 0; k < answerA[i].GetLength(1); k++) - { - Assert.AreEqual(answerA[i][j, k], inputA[i][j, k]); - } - } - Assert.AreEqual(answerB[i].GetLength(0), inputB[i].GetLength(0)); - Assert.AreEqual(answerB[i].GetLength(1), inputB[i].GetLength(1)); - for (int j = 0; j < answerB[i].GetLength(0); j++) - { - for (int k = 0; k < answerB[i].GetLength(1); k++) - { - Assert.AreEqual(answerB[i][j, k], inputB[i][j, k]); - } - } - } - } - [TestMethod] - public void Test03() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[10] { 0, 0, 0, 2, 2, 2, 0, 3, 2, 2 }; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task3(input[i]); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test04() - { - // Arrange - var inputA = _data.GetMatrixes(); - var inputB = _data.GetMatrixes(); - Array.Reverse(inputB); - var answerA = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 11}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {15}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 6}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 11, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 18, -17}, - {0, -2, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 11}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 13, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5}, - {5, 19, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - } - }; - var answerB = new int[][,] { - new int[,] { - {1, 2, 3, 4, -5}, - {5, 19, -17, 11, 7}, - {-9, -10, -11, -14, -15}, - {-9, -10, -11, -14, -6}, - {0, -2, -3, -4, -5}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 13, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 11}, - }, - new int[,] { - {1, 2, 3}, - {5, 18, -17}, - {0, -2, -3}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 11, -19}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 6}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {15}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 11}, - {0, 1, 2, 3, 4, 5, 6}, - } - }; - // Act - for (int i = 0; i < answerA.Length; i++) - { - _main.Task4(inputA[i], inputB[i]); - } - // Assert - for (int i = 0; i < answerA.Length; i++) - { - Assert.AreEqual(answerA[i].GetLength(0), inputA[i].GetLength(0)); - for (int j = 0; j < answerA[i].GetLength(0); j++) - { - Assert.AreEqual(answerA[i].GetLength(1), inputA[i].GetLength(1)); - for (int k = 0; k < answerA[i].GetLength(1); k++) - { - Assert.AreEqual(answerA[i][j, k], inputA[i][j, k]); - } - } - Assert.AreEqual(answerB[i].GetLength(0), inputB[i].GetLength(0)); - for (int j = 0; j < answerB[i].GetLength(0); j++) - { - Assert.AreEqual(answerB[i].GetLength(1), inputB[i].GetLength(1)); - for (int k = 0; k < answerB[i].GetLength(1); k++) - { - Assert.AreEqual(answerB[i][j, k], inputB[i][j, k]); - } - } - } - } - [TestMethod] - public void Test05() - { - // Arrange - var inputA = _data.GetMatrixes(); - var inputB = _data.GetMatrixes(); - Array.Reverse(inputB); - var answerA = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 2}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, -10}, - {13, 14, 15, 16, 17, 18, -10}, - {0, 1, 2, 3, 4, 5, -2}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 7, 3, 4, -5}, - {5, 11, -17, 11, 7}, - {-9, 15, -11, -14, -15}, - {-9, 19, -11, -14, -6}, - {0, 6, -3, -4, -5}, - } - }; - var answerB = new int[][,] { - new int[,] { - {1, 7, 3, 4, -5}, - {5, 11, -17, 11, 7}, - {-9, 15, -11, -14, -15}, - {-9, 19, -11, -14, -6}, - {0, 6, -3, -4, -5}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3}, - {5, 11, -17}, - {0, -2, -3}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {1, 2, 4, 6}, - {5, -6, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 2}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, -10}, - {13, 14, 15, 16, 17, 18, -10}, - {0, 1, 2, 3, 4, 5, -2}, - } - }; - // Act - for (int i = 0; i < answerA.Length; i++) - { - _main.Task5(inputA[i], inputB[i]); - } - // Assert - for (int i = 0; i < answerA.Length; i++) - { - Assert.AreEqual(answerA[i].GetLength(0), inputA[i].GetLength(0)); - for (int j = 0; j < answerA[i].GetLength(0); j++) - { - Assert.AreEqual(answerA[i].GetLength(1), inputA[i].GetLength(1)); - for (int k = 0; k < answerA[i].GetLength(1); k++) - { - Assert.AreEqual(answerA[i][j, k], inputA[i][j, k]); - } - } - Assert.AreEqual(answerB[i].GetLength(0), inputB[i].GetLength(0)); - for (int j = 0; j < answerB[i].GetLength(0); j++) - { - Assert.AreEqual(answerB[i].GetLength(1), inputB[i].GetLength(1)); - for (int k = 0; k < answerB[i].GetLength(1); k++) - { - Assert.AreEqual(answerB[i][j, k], inputB[i][j, k]); - } - } - } - } - [TestMethod] - public void Test06A() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {-6, 2, 4, 6}, - {5, -5, 7, 11}, - {-1, 4, 1, 6}, - {1, 4, 5, 6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {-3, 2, 3}, - {5, 1, -17}, - {0, -2, 11}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {-14, 2, 3, 4, -5}, - {5, -11, -17, 11, 7}, - {-9, -10, -5, -14, -15}, - {-9, -10, -11, 1, -6}, - {0, -2, -3, -4, 11}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task6(input[i], _main.SortDiagonalAscending); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test06B() - { - // Arrange - var input = _data.GetMatrixes(); - var answer = new int[][,] { - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, 9, 10, 11}, - {9, 10, 11, 12, 13, 14, 15}, - {13, 14, 15, 16, 17, 18, 19}, - {0, 1, 2, 3, 4, 5, 6}, - }, - new int[,] { - {1}, - {5}, - {9}, - {13}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6}, - {5, 6, 7, 8, 9, 11}, - {0, 2, 3, 4, 5, 6}, - }, - new int[,] { - {6, 2, 4, 6}, - {5, 1, 7, 11}, - {-1, 4, -5, 6}, - {1, 4, 5, -6}, - }, - new int[,] { - {1, 2, 3, 4, 5, 6, 7}, - {5, 6, 7, 8, -9, 10, 11}, - {9, 10, -11, -12, -13, -14, -15}, - {-13, -14, 15, 16, 17, 18, -19}, - }, - new int[,] { - {11, 2, 3}, - {5, 1, -17}, - {0, -2, -3}, - }, - new int[,] { - {-9, -10, -11, -14, -15, 6}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, -15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - }, - new int[,] { - {1, 2, 3, 4, -5, -6, -7}, - {5, 11, -17, 11, -10, 6, 5}, - {-9, -10, -11, -14, -15, -16, 1}, - {-9, -10, -11, -14, 15, -6, -2}, - {-9, -10, -11, -14, -15, 6, 4}, - {5, 11, -17, 11, -10, 6, -5}, - {1, 1, -2, 3, -4, 0, 0}, - {0, -2, -3, -4, -5, 0, 5}, - }, - new int[,] { - {11, 2, 3, 4, -5}, - {5, 1, -17, 11, 7}, - {-9, -10, -5, -14, -15}, - {-9, -10, -11, -11, -6}, - {0, -2, -3, -4, -14}, - } - }; - // Act - for (int i = 0; i < answer.Length; i++) - { - _main.Task6(input[i], _main.SortDiagonalDescending); - } - // Assert - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i].GetLength(0), input[i].GetLength(0)); - for (int j = 0; j < answer[i].GetLength(0); j++) - { - Assert.AreEqual(answer[i].GetLength(1), input[i].GetLength(1)); - for (int k = 0; k < answer[i].GetLength(1); k++) - { - Assert.AreEqual(answer[i][j, k], input[i][j, k]); - } - } - } - } - [TestMethod] - public void Test07() - { - // Arrange - var inputN = new int[10] { 1, 2, 3, 10, 10, 20, 9, 10, 12, 5 }; - var inputK = new int[10] { 1, 2, 2, 1, 10, 10, 10, 9, 2, 2 }; - var answer = new long[10] { 1, 1, 3, 10, 1, 184756, 0, 10, 66, 10 }; - var test = new long[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task7(inputN[i], inputK[i]); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test08A() - { - // Arrange - var inputV = new double[10] { 1, 2, 3.5, 0.1, 10, 99, 49, 50, 120, 0.75 }; - var inputA = new double[10] { 1, 0.2, 3.5, 11.1, 100, 0.1, 1, 1, 0.1, 0.25 }; - var answer = new double[10] { 55, 29.000000000000007, 192.5, 500.5, 4600, 994.4999999999998, 535, 545, 1204.4999999999998, 18.75 }; - var test = new double[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task8(inputV[i], inputA[i], _main.GetDistance); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i], E); - } - } - [TestMethod] - public void Test08B() - { - // Arrange - var inputV = new double[10] { 1, 2, 3.5, 0.1, 10, 99, 49, 50, 120, 0.75 }; - var inputA = new double[10] { 1, 0.2, 3.5, 11.1, 100, 0.1, 1, 1, 0.1, 0.25 }; - var answer = new double[10] { 14, 24, 8, 5, 2, 2, 3, 2, 1, 26 }; - var test = new double[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task8(inputV[i], inputA[i], _main.GetTime); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test09() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new int[5] { 89, 34, 1, 0, 84 }; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task9(input[i]); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test10A() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new int[5] { 54, 34, 6, 2, 42 }; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.CountPositive); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test10B() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new int[5] { 12, 12, 5, 5, 12 }; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.FindMax); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test10C() - { - // Arrange - var input = _data.GetArrayArrays(); - var answer = new int[5] { 10, 5, 9, 1, 10 }; - var test = new int[answer.Length]; - // Act - for (int i = 0; i < answer.Length; i++) - { - test[i] = _main.Task10(input[i], _main.FindMaxRowLength); - } - // Assert - Assert.AreEqual(answer.Length, test.Length); - for (int i = 0; i < answer.Length; i++) - { - Assert.AreEqual(answer[i], test[i]); - } - } - [TestMethod] - public void Test_FindMaxIndex() - { - double[] arr = { 5, -5, -9, 2, 9, 9, 9, 8.5, 0, -11 }; - int expected = 4; - int actual = _main.FindMaxIndex(arr); - Assert.AreEqual(expected, actual); - } - - [TestMethod] - public void Test_FindMaxRowIndexInColumn() - { - int[,] matrix = { - {7, 8, 10}, - {4, 5, 6}, - {1, 9, 3}, - {14, -10, 0} - }; - int expected = 2; - int actual = _main.FindMaxRowIndexInColumn(matrix, 1); - Assert.AreEqual(expected, actual); - } - [TestMethod] - public void Test_GetNegativeCountPerRow() - { - int[,] matrix = { - {-7, 8, 10}, - {4, 5, 6}, - {-1, -9, -3}, - {14, -10, 0} - }; - int[] expected = new int[] {1, 0, 3, 1}; - var actual = _main.GetNegativeCountPerRow(matrix); - CollectionAssert.AreEqual(expected.Cast().ToArray(), actual.Cast().ToArray()); - } - [TestMethod] - public void Test_FindMax() - { - int[,] matrix = { - {-7, 8, 10}, - {4, 5, 6}, - {-1, -9, -3}, - {14, -10, 14} - }; - int expected = 14, r = 3, c = 0; - var actual = _main.FindMax(matrix, out int row, out int col); - Assert.AreEqual(expected, actual); - Assert.AreEqual(r, row); - Assert.AreEqual(c, col); - } - [TestMethod] - public void Test_SwapColumns() - { - int[,] A = { - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9} - }; - - int[,] B = { - {9, 8, 7}, - {6, 5, 4}, - {3, 2, 1} - }; - - // обмен 1-го и 2-го столбцов - _main.SwapColumns(A, 0, B, 2); - - int[,] expectedA = { - {7, 2, 3}, - {4, 5, 6}, - {1, 8, 9} - }; - - CollectionAssert.AreEqual(expectedA.Cast().ToArray(), A.Cast().ToArray()); - } - [TestMethod] - public void Test_SortDiagonalAscending() - { - int[,] matrix = { - {9, 2, 3}, - {4, 7, 6}, - {5, 8, 1} - }; - - _main.SortDiagonalAscending(matrix); - - int[] expectedDiag = new int[] { 1, 7, 9 }; - int[] actualDiag = { matrix[0, 0], matrix[1, 1], matrix[2, 2] }; - CollectionAssert.AreEqual(expectedDiag, actualDiag); - } - - [TestMethod] - public void Test_SortDiagonalDescending() - { - int[,] matrix = { - {1, 2, 3}, - {4, 5, 6}, - {7, 8, 9} - }; - - _main.SortDiagonalDescending(matrix); - - int[] expectedDiag = { 9, 5, 1 }; - int[] actualDiag = { matrix[0, 0], matrix[1, 1], matrix[2, 2] }; - CollectionAssert.AreEqual(expectedDiag, actualDiag); - } - [TestMethod] - public void Test_Factorial() - { - long f0 = _main.Factorial(0); - long f5 = _main.Factorial(5); - long f10 = _main.Factorial(10); - - Assert.AreEqual(1, f0); - Assert.AreEqual(120, f5); - Assert.AreEqual(3628800, f10); - } - [TestMethod] - public void Test_GetDistance() - { - double v = 10, a = 1; - double expected = 10 * 10 + (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 +9); - double actual = _main.GetDistance(v, a); - Assert.AreEqual(145, actual, E); - } - [TestMethod] - public void Test_GetTime() - { - double v = 10, a = 2; - double actual = _main.GetTime(v, a); - int expected = 7; - Assert.AreEqual(expected, actual); - } - [TestMethod] - public void Test_SwapFromLeft() - { - int[] arr = { 1, 2, 3, 4, 5, 6 }; - _main.SwapFromLeft(arr); - int[] expected = { 2, 1, 4, 3, 6, 5 }; - CollectionAssert.AreEqual(expected, arr); - } - [TestMethod] - public void Test_SwapFromRight() - { - int[] arr = { 1, 2, 3, 4, 5, 6 }; - _main.SwapFromRight(arr); - int[] expected = { 2, 1, 4, 3, 6, 5 }; - CollectionAssert.AreEqual(expected, arr); - } - [TestMethod] - public void Test_GetSum() - { - int[] arr = { 10, 5, 3, 7, 9, -5 }; - int expected = 5 + 7 - 5; // индексы 1, 3, 5 - int actual = _main.GetSum(arr); - Assert.AreEqual(expected, actual); - } - [TestMethod] - public void Test_CountPositive() - { - int[][] array = { - new int[] { 1, -2, 3 }, - new int[] { -1, 0, 5 } - }; - int expected = 3; - int actual = _main.CountPositive(array); - Assert.AreEqual(expected, actual); - } - [TestMethod] - public void Test_FindMax_Jagged() - { - int[][] array = { - new int[] { 1, -2, 3 }, - new int[] { -1, 0, 5 } - }; - int expected = 5; - int actual = _main.FindMax(array); - Assert.AreEqual(expected, actual); - } - [TestMethod] - public void Test_FindMaxRowLength() - { - int[][] array = { - new int[] { 1, 2 }, - new int[] { 3, 4, 5, 6 } - }; - int expected = 4; - int actual = _main.FindMaxRowLength(array); - Assert.AreEqual(expected, actual); - } - } } +