Beispiel #1
0
        public void Iteration_ValidValues_ValidResult()
        {
            var matrix = new SymmetricMatix <int>(3, source);

            int i = 0;

            foreach (var item in matrix)
            {
                Assert.That(item, Is.EqualTo(matrixItems[i++]));
            }
        }
Beispiel #2
0
        public void Iteration_ChengingMatrix_InvalidOperationException()
        {
            var matrix = new SymmetricMatix <int>(3, source);

            Assert.Throws <InvalidOperationException>(() =>
            {
                foreach (var item in matrix)
                {
                    matrix[0, 0] = 1;
                }
            });
        }
Beispiel #3
0
        public void Indexer_ValidValues_ValidResult()
        {
            var matrix = new SymmetricMatix <int>(3, source);

            int k = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Assert.That(matrix[i, j], Is.EqualTo(matrixItems[k++]));
                }
            }
        }
        public void SymmetricMatrixInsert_ValidIntFormat_ValidResult()
        {
            int[,] arr = new int[, ] {
                { 0, 1, 2 },
                { 1, 3, 4 },
                { 2, 4, 5 }
            };

            SymmetricMatix <int> sm = new SymmetricMatix <int>(3, arr);

            sm.InsertElement(0, 2, 6);

            Assert.AreEqual(arr[0, 2], 6);
            Assert.AreEqual(arr[2, 0], 6);
        }
Beispiel #5
0
        public void AdditionOperator_SymmetricAndSquareMatrices_ValidResult()
        {
            var matrix1 = new SymmetricMatix <int>(3, source);
            var matrix2 = new SquareMatrix <int>(3, matrixItems);

            var result         = matrix1 + matrix2;
            var expectedResult = new int[] { 2, 4, 8, 4, 6, 10, 8, 10, 12 };

            int i = 0;

            foreach (var item in result)
            {
                Assert.That(item, Is.EqualTo(expectedResult[i++]));
            }

            Assert.That(result.GetType(), Is.EqualTo(typeof(SquareMatrix <int>)));
        }
        public void MatrixSummator_ValidIntFormat_ValidResult()
        {
            int[,] arr = new int[, ] {
                { 0, 1, 2 },
                { 1, 3, 4 },
                { 2, 4, 5 }
            };

            int[,] arr2 = new int[, ] {
                { 0, 0, 0 },
                { 0, 3, 0 },
                { 0, 0, 5 }
            };

            SymmetricMatix <int> sm = new SymmetricMatix <int>(3, arr);
            DiagonalMatrix <int> dm = new DiagonalMatrix <int>(3, arr2);

            var t = MatrixSummator.SumTwoMatrix(dm, sm);

            Assert.AreEqual(t[1, 1], 6);
            Assert.AreEqual(t[1, 2], 4);
        }