Exemplo n.º 1
0
        public void MatrixHierarchyAdditionTest()
        {
            var squareMatrix = new int[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
            };
            var diagonalMatrix = new int[, ] {
                { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }
            };
            var symmetricalMatrix = new int[, ] {
                { 1, 2, 3 }, { 2, 1, 4 }, { 3, 4, 1 }
            };

            var resultSquareSquare = new[, ] {
                { 2, 4, 6 }, { 8, 10, 12 }, { 14, 16, 18 }
            };
            var resultSquareDiagonal = new[, ] {
                { 2, 2, 3 }, { 4, 6, 6 }, { 7, 8, 10 }
            };
            var resultSquareSymmetrical = new[, ] {
                { 2, 4, 6 }, { 6, 6, 10 }, { 10, 12, 10 }
            };

            var resultDiagonalDiagonal = new[, ] {
                { 2, 0, 0 }, { 0, 2, 0 }, { 0, 0, 2 }
            };
            var resultDiagonalSquare = new[, ] {
                { 2, 0, 0 }, { 0, 6, 0 }, { 0, 0, 10 }
            };
            var resultDiagonalSymmetrical = new[, ] {
                { 2, 0, 0 }, { 0, 2, 0 }, { 0, 0, 2 }
            };

            var resultSymmetricalSymmetrical = new[, ] {
                { 2, 4, 6 }, { 4, 2, 8 }, { 6, 8, 2 }
            };
            var resultSymmetricalSquare = new[, ] {
                { 2, 4, 6 }, { 6, 6, 10 }, { 10, 12, 10 }
            };
            var resultSymmetricalDiagonal = new[, ] {
                { 2, 2, 3 }, { 2, 2, 4 }, { 3, 4, 2 }
            };

            var matrixSquare      = new SquareMatrix <int>(squareMatrix);
            var matrixDiagonal    = new DiagonalMatrix <int>(diagonalMatrix);
            var matrixSymmetrical = new SymmetricalMatrix <int>(symmetricalMatrix);


            var sumSquareSquare = MatrixExtension <int> .Addition(matrixSquare, matrixSquare);

            var sumSquareDiagonal = MatrixExtension <int> .Addition(matrixSquare, matrixDiagonal);

            var sumSquareSymmetrical = MatrixExtension <int> .Addition(matrixSquare, matrixSymmetrical);

            var sumDiagonalDiagonal = MatrixExtension <int> .Addition(matrixDiagonal, matrixDiagonal);

            var sumDiagonalSquare = MatrixExtension <int> .Addition(matrixDiagonal, matrixSquare);

            var sumDiagonalSymmetrical = MatrixExtension <int> .Addition(matrixDiagonal, matrixSymmetrical);

            var sumSymmetricalSymmetrical = MatrixExtension <int> .Addition(matrixSymmetrical, matrixSymmetrical);

            var sumSymmetricalSquare = MatrixExtension <int> .Addition(matrixSymmetrical, matrixSquare);

            var sumSymmetricalDiagonal = MatrixExtension <int> .Addition(matrixSymmetrical, matrixDiagonal);

            CollectionAssert.AreEqual(resultSquareSquare, sumSquareSquare.GetMatrix());
            CollectionAssert.AreEqual(resultSquareDiagonal, sumSquareDiagonal.GetMatrix());
            CollectionAssert.AreEqual(resultSquareSymmetrical, sumSquareSymmetrical.GetMatrix());

            CollectionAssert.AreEqual(resultDiagonalDiagonal, sumDiagonalDiagonal.GetMatrix());
            CollectionAssert.AreEqual(resultDiagonalSquare, sumDiagonalSquare.GetMatrix());
            CollectionAssert.AreEqual(resultDiagonalSymmetrical, sumDiagonalSymmetrical.GetMatrix());

            CollectionAssert.AreEqual(resultSymmetricalSymmetrical, sumSymmetricalSymmetrical.GetMatrix());
            CollectionAssert.AreEqual(resultSymmetricalSquare, sumSymmetricalSquare.GetMatrix());
            CollectionAssert.AreEqual(resultSymmetricalDiagonal, sumSymmetricalDiagonal.GetMatrix());
        }