public void SumExtensionMethod_ComputeSumOfTwoDiagonalMatrices() { int[] testArray = { 4, 6, 2 }; var matrix = new DiagonalMatrix<int>(testArray); var other = new DiagonalMatrix<int>(testArray); var actualResult = matrix.Sum(other, (m, n) => m + n); int[][] expectedArray = { new[] { 8, 0, 0 }, new[] { 0, 12, 0 }, new[] { 0, 0, 4 } }; var expectedResult = new SquareMatrix<int>(expectedArray); for (int i = 0; i < matrix.Order; i++) { for (int j = 0; j < matrix.Order; j++) { Assert.AreEqual(expectedResult[i, j], actualResult[i, j]); } } }
public void DiagonalMatrixSumTest() { int[] array = new int[] { 1, 2 }; int[] ex = new int[] { 2, 4 }; DiagonalMatrix <int> expected = new DiagonalMatrix <int>(ex); DiagonalMatrix <int> actual = new DiagonalMatrix <int>(array); Assert.AreEqual(expected, actual.Sum(actual)); }
public void Sum() { var matrix = new DiagonalMatrix <int>(1, 0, 0, 0, 5, 0, 0, 0, 9); var actual = matrix.Sum(matrix); foreach (var variable in actual) { Console.WriteLine(variable); } }
public void SumMatrix() { // arrange int[,] expected = { { 4, 5, 3 }, { 5, 7, 1 }, { 3, 1, 5 } }; int[] arrayDiagonal = new int[] { 2, 5, 3 }; int[] arraySymmetrical = new int[] { 2, 5, 3, 2, 1, 2 }; int length = 3; Func <int, int, int> func = (firstElement, secondElement) => firstElement + secondElement; // act SquareMatrix <int> diagonal = new DiagonalMatrix <int>(arrayDiagonal, func); SquareMatrix <int> symmetric = new SymmetricalMatrix <int>(arraySymmetrical, length, func); // assert SquareMatrix <int> squareMatrix = diagonal.Sum(symmetric); for (int i = 0; i < length; i++) { for (int j = 0; j < length; j++) { Assert.AreEqual(expected[i, j], squareMatrix[i, j]); } } }