public void Add_SquareAndSymmetrical_ReturnSquareMatrix() { var matrix = new int[, ] { { 1, 2 }, { 4, 5 } }; var square = new SquareMatrix <int>(matrix); int[,] symmetrical = new int[, ] { { 1, 5 }, { 5, 7 } }; var diagonalMatrix = new SymmetricalMatrix <int>(symmetrical); var result = square.Add(diagonalMatrix); int[,] expectedValues = { { 2, 7 }, { 9, 12 } }; for (int i = 0; i < result.Size; i++) { for (int j = 0; j < result.Size; j++) { Assert.AreEqual(expectedValues[i, j], result[i, j]); } } }
static void Main(string[] args) { SymmetricalMatrix <string> symMatrix = new SymmetricalMatrix <string>(3); symMatrix.MatrixEvent += Handler2; symMatrix[1, 2] = "abc"; symMatrix[0, 1] = "aaa"; int[] values = new int[] { 10, 20, 30, 40 }; DiagonalMatrix <int> diagMatrix = new DiagonalMatrix <int>(values); SquareMatrix <int> .MatrixDelegate del = diagMatrix.Method; diagMatrix.MatrixEvent += Handler1; diagMatrix[3, 3] = 17; SquareMatrix <int> sqMatrix = new SquareMatrix <int>(4); sqMatrix[0, 1] = 12; sqMatrix[3, 0] = 78; SquareMatrix <int> newMatrix = ExtendedMatrix <int> .GetSum(sqMatrix, diagMatrix); Console.ReadLine(); }
public void SetUp() { int[,] arrayA = { { 4, 6, 3 }, { 4, 6, 3 }, { 4, 6, 3 } }; int[,] arrayB = { { 5, 2, 7 }, { 5, 2, 7 }, { 5, 2, 7 } }; string[,] arrayStr = { { "asd", "aqwe" }, { "sakjd", "qwrb" } }; // All of them have integer values this.square = new SquareMatrix <int>(arrayA); this.symmetric = new SymmetricalMatrix <int>(arrayB); this.squareString = new SquareMatrix <string>(arrayStr); this.diagonalString = new DiagonalMatrix <string>(2); // Full of nulls this.diagonal = new DiagonalMatrix <int>(arrayB); // Length is 3 this.diagonalDiff = new DiagonalMatrix <int>(5); }
public void TestAdd2() { int[][] matrix = new int[][] { new [] { 1, 0, 0 }, new [] { 0, 1, 0 }, new [] { 0, 0, 1 } }; var matrix1 = new SymmetricalMatrix <int>(matrix); int[][] matrixx = new int[][] { new [] { 1, 0, 0 }, new [] { 0, 1, 0 }, new [] { 0, 0, 1 } }; var matrix2 = new DiagonalMatrix <int>(matrixx); int[][] expected = new int[][] { new [] { 2, 0, 0 }, new [] { 0, 2, 0 }, new [] { 0, 0, 2 } }; var actual = new MatrixVisitor <int>().Add(matrix1, matrix2); CollectionAssert.AreEqual(expected, actual.ToArray()); }
static void Main(string[] args) { try { SquareMatrix<int> squareMatrix1 = new SquareMatrix<int>(new int[,] { { 1, 2 }, { 3, 4 } }); SquareMatrix<int> squareMatrix2 = new SquareMatrix<int>(new int[,] { { 1, 2 }, { 3, 4 } }); //SquareMatrix<int> squareMatrix2 = new SquareMatrix<int>(new int[,]{{1,2,3},{4,5,6}}); SymmetricalMatrix<int> symmetricalMatrix1 = new SymmetricalMatrix<int>((new int[,] { { 1, 1 }, { 1, 4 } })); //SymmetricalMatrix<int> symmetricalMatrix2 = new SymmetricalMatrix<int>((new int[,] { { 1, 2 }, { 1, 4 } })); SquareMatrix<int> squareMatrix3 = new SymmetricalMatrix<int>((new int[,] { { 1, 1 }, { 1, 4 } })); SymmetricalMatrix<int> symmetricalMatrix3 = (SymmetricalMatrix<int>)squareMatrix3; DiagonalMatrix<int> diagonalMatrix1 = new DiagonalMatrix<int>(new int[,] { { 1, 0 }, { 0, 1 } }); var client = new Client1<int>(squareMatrix1); var client2 = new Client1<int>(symmetricalMatrix1); squareMatrix1[0, 0] = 2; symmetricalMatrix1[1, 0] = 2; Console.ReadKey(); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadKey(); } }
public void EqualityTestInt(int[,] elements) { var lhs = new SymmetricalMatrix <int>(elements); var rhs = new SymmetricalMatrix <int>(elements); Assert.IsTrue(lhs.Equals(rhs)); }
public void EqualityTestString(string[,] elements) { var lhs = new SymmetricalMatrix <string>(elements); var rhs = new SymmetricalMatrix <string>(elements); Assert.IsTrue(lhs.Equals(rhs)); }
public void Add_TwoSymmetricalMatrices_ReturnSymmetricalMatrix() { var matrix = new int[, ] { { 11, 2, -8 }, { 2, 2, 10 }, { -8, 10, 5 } }; var first = new SymmetricalMatrix <int>(matrix); var second = new SymmetricalMatrix <int>(matrix); var result = first.Add(second); var expectedValues = new int[, ] { { 22, 4, -16 }, { 4, 4, 20 }, { -16, 20, 10 } }; for (int i = 0; i < result.Size; i++) { for (int j = 0; j < result.Size; j++) { Assert.AreEqual(expectedValues[i, j], result[i, j]); } } }
public void Add_DiagonalAndSymmetricalMatrices_ReturnSymmetricalMatrix() { var valuesForSymmetrical = new int[, ] { { 11, 2, -8 }, { 2, 2, 10 }, { -8, 10, 5 } }; var valuesForDiagonal = new int[, ] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; var diagonalMatrix = new DiagonalMatrix <int>(valuesForDiagonal); var symmetricalMatrix = new SymmetricalMatrix <int>(valuesForSymmetrical); var expectedValues = new int[, ] { { 12, 2, -8 }, { 2, 3, 10 }, { -8, 10, 6 } }; var result = diagonalMatrix.Add(symmetricalMatrix); for (int i = 0; i < result.Size; i++) { for (int j = 0; j < result.Size; j++) { Assert.AreEqual(expectedValues[i, j], result[i, j]); } } }
public void SumOfTest1() { int[][] arr = new int[][] { new int[] { 1, 0, 0 }, new int[] { 0, 3, 0 }, new int[] { 0, 0, 6 } }; int[][] arr1 = new int[][] { new int[] { 1, 1 }, new int[] { 1, 3 } }; DiagonalMatrix <int> diagMatrix = new DiagonalMatrix <int>(arr); SymmetricalMatrix <int> symmMatrix = new SymmetricalMatrix <int>(arr1); int[][] expected = new int[][] { new int[] { 2, 1, 0 }, new int[] { 1, 6, 0 }, new int[] { 0, 0, 6 } }; SquareMatrix <int> actual = diagMatrix + symmMatrix; Assert.AreEqual(actual.Array, expected); }
public void CtorSymmetricalMatrix_CheckCreation() { // arrange int[,] expected = { { 2, 5, 3 }, { 5, 2, 1 }, { 3, 1, 2 } }; int[] array = new int[] { 2, 5, 3, 2, 1, 2 }; int length = 3; Func <int, int, int> func = (firstElement, secondElement) => firstElement + secondElement; // act SquareMatrix <int> symmetric = new SymmetricalMatrix <int>(array, length, func); // assert for (int i = 0; i < length; i++) { for (int j = 0; j < length; j++) { Assert.AreEqual(expected[i, j], symmetric[i, j]); } } }
public void PlustOperator_SymmetricalAndSymmetrical_SymmetricalMatrix() { SymmetricalMatrix <int> inMatrix = new SymmetricalMatrix <int>(symmetricalArray, new IntSum()); SymmetricalMatrix <int> outMatrix = inMatrix + inMatrix; Assert.AreEqual(symmetricalResult, outMatrix.Array); }
public void Create_SizePassed() { var size = 3; var matrix = new SymmetricalMatrix <int>(size); Assert.AreEqual(size, matrix.Size); }
public void CtorSymmMatrix_ThowsArgumentException() { SymmetricalMatrix <int> matr; Assert.Catch <ArgumentException>(() => matr = new SymmetricalMatrix <int>(new int[, ] { { 1, 4, 0 }, { 3, 2, 6 }, { 0, 6, 5 } })); }
public void PlustOperator_SymmetricalAndDiagonal_SquareMatrix() { SymmetricalMatrix <int> inMatrix1 = new SymmetricalMatrix <int>(symmetricalArray, new IntSum()); DiagonalMatrix <int> inMatrix2 = new DiagonalMatrix <int> (diagonalArray, new IntSum()); SquareMatrix <int> outMatrix = inMatrix1 + inMatrix2; Assert.AreEqual(symDiagResult, outMatrix.Array); }
public void CtorSymmMatrix_Successully() { SymmetricalMatrix <int> matr; Assert.DoesNotThrow(() => matr = new SymmetricalMatrix <int>(new int[, ] { { 1, 3, 0 }, { 3, 2, 6 }, { 0, 6, 5 } })); }
public void SymmetricalMatrixTest_ValueChange_Event_Succed() { SymmetricalMatrix <int> symmetricalMatrix = new SymmetricalMatrix <int>(5); symmetricalMatrix.ChangeValue += (s, e) => { Assert.Pass($"{e.i}.{e.j}, old - {e.OldValue} , new - {e.NewValue}"); }; symmetricalMatrix[0, 0] = 10; }
public string[,] AddTestString(string[,] elements) { var lhs = new SymmetricalMatrix <string>(elements); var rhs = new SymmetricalMatrix <string>(elements); lhs = lhs.Add(rhs) as SymmetricalMatrix <string>; return(lhs?.ToArray()); }
public int[,] AddTestInt(int[,] elements) { var lhs = new SymmetricalMatrix <int>(elements); var rhs = new SymmetricalMatrix <int>(elements); lhs = lhs.Add(rhs) as SymmetricalMatrix <int>; return(lhs?.ToArray()); }
public int[,] AddDiagonalAndSymmetricalTestInt(int[,] elements) { var lhs = new DiagonalMatrix <int>(elements); var rhs = new SymmetricalMatrix <int>(elements); rhs = rhs.Add(lhs) as SymmetricalMatrix <int>; return(rhs?.ToArray()); }
public void SymmetricalMatrixChangeEventTest() { GeneralMatrix<int> matrix = new SymmetricalMatrix<int>(new int[3, 3] { { 1, 2, 3 }, { 2, 1, 2 }, { 3, 2, 1 } }); Subscribe(matrix); matrix[0, 1] = 5; Assert.AreEqual<string>("SymmetricalMatrix: changed both symmetric and request elements.", message); matrix[1, 1] = 5; Assert.AreEqual<string>("SymmetricalMatrix: changed element on main diagonal.", message); Unsubscribe(matrix); }
public void SymmetricalMatrix_Event_ValueChange_NUnit() { // Arrange SymmetricalMatrix <int> symmetricalMatrix = new SymmetricalMatrix <int>(10); // Act symmetricalMatrix.Change += (s, e) => { Assert.Pass("The elements have been changed"); }; symmetricalMatrix[0, 0] = 20; }
public void Indexer_SetValue_ValuesAreSetted() { int[,] values = new int[, ] { { 1, 5 }, { 5, 7 } }; var matrix = new SymmetricalMatrix <int>(values); matrix[0, 1] = 222; Assert.AreEqual(222, matrix[0, 1]); Assert.AreEqual(222, matrix[1, 0]); }
public void Add_SquareAddToSymmetricalMatrixTests(SquareMatrix <int> firstMatrix, SymmetricalMatrix <int> secondMatrix, SymmetricalMatrix <int> expectedMatrix) { SymmetricalMatrix <int> result = firstMatrix.Add(secondMatrix); for (int i = 0; i < result.Order; i++) { for (int j = 0; j < result.Order; j++) { Assert.AreEqual(expectedMatrix[i, j], result[i, j]); } } }
public void SymmetricalMatrixTest_Pass_SymmetricalMatrix_Succed() { int[,] paramMatrix = new int[, ] { { 3, 5, 4 }, { 5, 6, 8 }, { 4, 8, 7 } }; SymmetricalMatrix <int> symmetricalMatrix = new SymmetricalMatrix <int>(paramMatrix); Assert.Pass(); }
public void MatrixHierarchyAdditionTest2() { var array1 = new string[][] { new string[] { "-3" }, new string[] { "6", "-5" }, new string[] { "5", "7", "4" } }; var array2 = new string[] { "ab", "cd", "ef" }; var resultArray = new string[, ] { { "-3ab", "6", "5" }, { "6", "-5cd", "7" }, { "5", "7", "4ef" } }; var matrixA = new SymmetricalMatrix <string>(array1); var matrixB = new DiagonalMatrix <string>(array2); var sum = MatrixExtension <string> .Add(matrixA, matrixB); CollectionAssert.AreEqual(resultArray, sum.ToArray()); }
public void Equals_SymmetricalMatrixEqualSquareMatrix_TrueReturned() { var a = new SymmetricalMatrix<int>(new int[,]{ {1,1}, {1,2}}); var b = new SquareMatrix<int>(new int[,]{ {1,1}, {1,2}}); bool result = a.Equals(b); Assert.AreEqual(true, result); }
public void Test_SettingObjectOutsideTheDiagonal() { DiagonalMatrix <int> matrix = new DiagonalMatrix <int>(4); matrix[3, 1] = 169; Assert.AreEqual(0, matrix[3, 1]); SymmetricalMatrix <int> second = new SymmetricalMatrix <int>(10); second[1, 5] = 184; Assert.AreEqual(184, second[1, 5]); Assert.AreEqual(184, second[5, 1]); }
public void SymmetricalMatrix_InputCorrectSymMatrix_CheckIsMatrix_NUnit() { // Arrange int[,] matrix = new int[, ] { { 3, 5, 4 }, { 5, 6, 8 }, { 4, 8, 7 } }; SymmetricalMatrix <int> symmetricalMatrix = new SymmetricalMatrix <int>(matrix); // Assert Assert.Pass(); }
protected override SymmetricalMatrix <T> Visit(SymmetricalMatrix <T> lhs, SymmetricalMatrix <T> rhs) { this.Validate(lhs, rhs); SymmetricalMatrix <T> symmetricalMatrix = new SymmetricalMatrix <T>(rhs.Size); for (int i = 0; i < rhs.Size; i++) { for (int j = 0; j < rhs.Size; j++) { symmetricalMatrix[i, j] = AddViaDynamic(lhs[i, j], rhs[i, j]); } } return(symmetricalMatrix); }
public void Create_SymmetricalMatrixPassed_Created() { int[,] values = new int[, ] { { 1, 5 }, { 5, 7 } }; var matrix = new SymmetricalMatrix <int>(values); for (int i = 0; i < matrix.Size; i++) { for (int j = 0; j < matrix.Size; j++) { Assert.AreEqual(values[i, j], matrix[i, j]); } } }
public void OperationMatrixTest_Add_ArgumentNullException() { int[,] paramMatrix = new int[, ] { { 3, 5, 4 }, { 5, 6, 8 }, { 4, 8, 7 } }; SquareMatrix <int> squareMatrix = new SquareMatrix <int>(paramMatrix); SymmetricalMatrix <int> symmetricalMatrix = null; Assert.Throws <ArgumentNullException>( () => squareMatrix.Add(symmetricalMatrix)); }
public void Indexer_AddNewElementToMatrixTests(int element, int indexI, int indexJ, int order) { SymmetricalMatrix <int> matrix = new SymmetricalMatrix <int>(order); Handler handler = new Handler(); matrix.ValueChanged += handler.Message; int oldElement = matrix[indexI, indexJ]; matrix[indexI, indexJ] = element; Assert.AreEqual( string.Format("The element of the matrix was changed!\nRow index: {0}\nColumn index: {1}\nOld value: {2}\nNew value: {3}", indexI, indexJ, oldElement, element), handler.Result); Assert.AreEqual(matrix[indexI, indexJ], matrix[indexJ, indexI]); }
static void Main(string[] args) { int[] ints = new int[4] { 1, 2, 3, 4 }; SquareMatrix<int> m = new SquareMatrix<int>(); m.ElementChanged += m_ElementChanged; Console.WriteLine(m.ToString()); m[1, 1] = 5; Console.WriteLine(m.ToString()); SymmetricalMatrix<int> s = new SymmetricalMatrix<int>(new int[] {1, 2, 3, 4, 5, 6}, 3); Console.WriteLine(s.ToString()); s.ElementChanged += m_ElementChanged; s[1, 2] = 60; Console.WriteLine(s.ToString()); SquareMatrix<int> m1 = new SquareMatrix<int>(new int[] { 1, 4, 5, 7 }, 2); SquareMatrix<int> m2 = new SquareMatrix<int>(new int[] { 1, 4, 5, 8 }, 2); Console.WriteLine(m1.CalculateOperation(m2, (a, b) => a + b)); Console.ReadLine(); }
public void SymmetricalMatrixConstructor_NullInputMatrixExceptionTest() { GeneralMatrix<int> matrix1 = new SymmetricalMatrix<int>(null); }
public int IndexatorTest_Int_SymmetricalMatrix(int[] array, int length, int i, int j) { SymmetricalMatrix<int> m = new SymmetricalMatrix<int>(array, length); return m[i, j]; }
public void SymmetricalMatrixSetterTest() { GeneralMatrix<int> matrix = new SymmetricalMatrix<int>(new int[3, 3] { { 1, 2, 3 }, { 2, 1, 2 }, { 3, 2, 1 } }); matrix[0, 1] = 5; matrix[1, 1] = 10; Assert.AreEqual<int>(5, matrix[0, 1]); Assert.AreEqual<int>(5, matrix[1, 0]); Assert.AreEqual<int>(10, matrix[1, 1]); }
public void SymmetricalMatrixConstructor_NotSymmetricalInputMatrixExceptionTest() { GeneralMatrix<int> matrix = new SymmetricalMatrix<int>(new int[3, 3] { { 1, 2, 1 }, { 2, 1, 2 }, { 3, 2, 1 } }); }
public void SymmetricMatrixAdditionTest() { GeneralMatrix<int> matrix1 = new SymmetricalMatrix<int>(new int[3, 3] { { 1, 2, 3 }, { 2, 1, 2 }, { 3, 2, 1 } }); GeneralMatrix<int> matrix2 = new SquareMatrix<int>(new int[3, 3] { { 2, 7, 3 }, { 4, 0, 2 }, { 3, 6, 2 } }); matrix1.SumWith(matrix2, AdditionMethod); Assert.AreEqual<int>(3, matrix1[0, 0]); Assert.AreEqual<int>(13, matrix1[0, 1]); Assert.AreEqual<int>(9, matrix1[0, 2]); Assert.AreEqual<int>(13, matrix1[1, 0]); Assert.AreEqual<int>(1, matrix1[1, 1]); Assert.AreEqual<int>(10, matrix1[1, 2]); Assert.AreEqual<int>(9, matrix1[2, 0]); Assert.AreEqual<int>(10, matrix1[2, 1]); Assert.AreEqual<int>(3, matrix1[2, 2]); }