Пример #1
0
 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]);
         }
     }
 }
Пример #2
0
 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]);
         }
     }
 }
Пример #3
0
        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]);
                }
            }
        }
Пример #4
0
 /// <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];
         }
     }
 }
Пример #5
0
        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.");
            }
        }
Пример #6
0
        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++;
                }
            }
        }
Пример #7
0
        /// <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];
                }
            }
        }
Пример #8
0
 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);
     }
 }
Пример #9
0
        /// <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);
        }
Пример #10
0
 private static void ConstructorTest(int order, AbstractSquareMatrix <int> abstractSquareMatrix)
 {
     Assert.IsTrue(14 == abstractSquareMatrix.Order);
 }
Пример #11
0
        public void Add_AddingMatrixIsNull_ThrowsArgumentNullException()
        {
            AbstractSquareMatrix <int> sourse = symmetricMatrix;

            Assert.Throws <ArgumentNullException>(() => sourse.Add(null));
        }
Пример #12
0
        public void Add_SourceMatrixIsNull_ThrowsArgumentNullException()
        {
            AbstractSquareMatrix <int> sourse = null;

            Assert.Throws <ArgumentNullException>(() => sourse.Add(symmetricMatrix));
        }
Пример #13
0
 /// <summary>
 /// Dynamics the visit.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 public void DynamicVisit(AbstractSquareMatrix <T> matrix)
 {
     Visit((dynamic)matrix);
 }