private static void IndexerTest(int[,] array, AbstractSquareMatrix <int> abstractSquareMatrix) { for (int i = 0; i < abstractSquareMatrix.Order; i++) { for (int j = 0; j < abstractSquareMatrix.Order; j++) { Assert.AreEqual(array[i, j], abstractSquareMatrix[i, j]); } } }
private void Add(AbstractSquareMatrix <T> matrix) { for (int i = 0; i < matrix.Order; i++) { for (int j = 0; j < matrix.Order; j++) { this.Result[i, j] = Add(this.Result[i, j], matrix[i, j]); } } }
private static void ToArrayTest(int[,] array, AbstractSquareMatrix <int> abstractSquareMatrix) { var temp = abstractSquareMatrix.ToArray(); for (int i = 0; i < abstractSquareMatrix.Order; i++) { for (int j = 0; j < abstractSquareMatrix.Order; j++) { Assert.AreEqual(array[i, j], temp[i, j]); } } }
/// <inheritdoc /> public SquareMatrix(AbstractSquareMatrix <T> sorceMatrix) : base(sorceMatrix) { this.matrix = new T[this.Order * this.Order]; for (int i = 0; i < this.Order; i++) { for (int j = 0; j < this.Order; j++) { int index = ComputeIndex(i, j, this.Order); this.matrix[index] = sorceMatrix[i, j]; } } }
private void ValidateMatrix(AbstractSquareMatrix <T> matrix) { if (matrix == null) { throw new ArgumentNullException(nameof(matrix)); } if (this.Result != null && this.Result.Order != matrix.Order) { throw new InvalidOperationException("Matrices order must match."); } }
private static void EnumeratorTest(int[,] array, AbstractSquareMatrix <int> abstractSquareMatrix) { int i = 0, j = 0; foreach (var element in abstractSquareMatrix) { Assert.AreEqual(array[i, j++], element); if (j == array.GetLength(1)) { j = 0; i++; } } }
/// <inheritdoc /> /// <summary> /// Creates a matrix by transforming the <paramref name="sorceMatrix"/> into a symmetric matrix. /// </summary> public SymmetricMatrix(AbstractSquareMatrix <T> sorceMatrix) : base(sorceMatrix) { int k = ComputeMatrixArraySize(this.Order); this.matrix = new T[k]; k = 0; for (int i = 0; i < this.Order; i++) { for (int j = i; j < this.Order; j++) { this.matrix[k++] = sorceMatrix[i, j]; } } }
private void NormalizeResultType(AbstractSquareMatrix <T> matrix, Func <AbstractSquareMatrix <T> > creator) { if (this.Result is null) { this.Result = creator(); } else if (this.matrixTypePriority[this.Result.GetType()] > this.matrixTypePriority[matrix.GetType()]) { dynamic temp = this.Result; this.Result = creator(); this.Add(temp); } else { this.Add(matrix); } }
/// <summary> /// Adds the specified addind matrix. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sourceMatrix">The source matrix.</param> /// <param name="addindMatrix">The addind matrix.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// addindMatrix /// or /// addindMatrix /// </exception> public static AbstractSquareMatrix <T> Add <T>(this AbstractSquareMatrix <T> sourceMatrix, AbstractSquareMatrix <T> addindMatrix) { if (sourceMatrix == null) { throw new ArgumentNullException(nameof(addindMatrix)); } if (addindMatrix == null) { throw new ArgumentNullException(nameof(addindMatrix)); } var visitor = new AddVisitor <T>(); visitor.DynamicVisit(sourceMatrix); visitor.DynamicVisit(addindMatrix); return(visitor.Result); }
private static void ConstructorTest(int order, AbstractSquareMatrix <int> abstractSquareMatrix) { Assert.IsTrue(14 == abstractSquareMatrix.Order); }
public void Add_AddingMatrixIsNull_ThrowsArgumentNullException() { AbstractSquareMatrix <int> sourse = symmetricMatrix; Assert.Throws <ArgumentNullException>(() => sourse.Add(null)); }
public void Add_SourceMatrixIsNull_ThrowsArgumentNullException() { AbstractSquareMatrix <int> sourse = null; Assert.Throws <ArgumentNullException>(() => sourse.Add(symmetricMatrix)); }
/// <summary> /// Dynamics the visit. /// </summary> /// <param name="matrix">The matrix.</param> public void DynamicVisit(AbstractSquareMatrix <T> matrix) { Visit((dynamic)matrix); }