コード例 #1
0
        public void MatrixComputationsTransposeTest()
        {
            for (Int32 matrixIndex = 0; matrixIndex < this.matrices.Length; matrixIndex++)
            {
                Matrix result = MatrixComputations.Transpose(this.matrices[matrixIndex]);

                for (Int32 rowIndex = 0; rowIndex < this.matrices[matrixIndex].NumberOfRows; rowIndex++)
                {
                    for (Int32 columnIndex = 0; columnIndex < this.matrices[matrixIndex].NumberOfColumns; columnIndex++)
                    {
                        result[columnIndex, rowIndex].ShouldBe(this.matrices[matrixIndex][rowIndex, columnIndex]);
                    }
                }
            }
        }
コード例 #2
0
        public void MatrixTransposeVectorTest()
        {
            // first vector
            Vector vector = new Vector(0);
            Matrix result = MatrixComputations.Transpose(vector);

            result.NumberOfColumns.ShouldBe(0);
            result.NumberOfRows.ShouldBe(1);

            // second vector
            vector = new Vector(1, 1, 1, 1);
            result = MatrixComputations.Transpose(vector);

            result.NumberOfColumns.ShouldBe(4);
            result.NumberOfRows.ShouldBe(1);
            result.ShouldAllBe(value => value == 1);

            // third vector
            vector = new Vector(3, 8, 54, 32);
            result = MatrixComputations.Transpose(vector);
            result.NumberOfColumns.ShouldBe(4);
            result.NumberOfRows.ShouldBe(1);

            result.NumberOfColumns.ShouldBe(4);
            result.NumberOfRows.ShouldBe(1);
            for (Int32 index = 0; index < vector.Size; index++)
            {
                result[0, index].ShouldBe(vector[index]);
            }

            // forth vector
            vector = new Vector(1.2, 5.8, 7.456, 15);
            result = MatrixComputations.Transpose(vector);
            result.NumberOfColumns.ShouldBe(4);
            result.NumberOfRows.ShouldBe(1);

            result.NumberOfColumns.ShouldBe(4);
            result.NumberOfRows.ShouldBe(1);
            for (Int32 index = 0; index < vector.Size; index++)
            {
                result[0, index].ShouldBe(vector[index]);
            }

            // exceptions
            Should.Throw <ArgumentNullException>(() => MatrixComputations.Transpose((Vector)null));
        }
コード例 #3
0
        public void MatrixTransposeMatrixTest()
        {
            for (Int32 matricesIndex = 0; matricesIndex < this.matrices.Length; matricesIndex++)
            {
                Matrix transponedMatrix = MatrixComputations.Transpose(this.matrices[matricesIndex]);
                transponedMatrix.NumberOfColumns.ShouldBe(this.matrices[matricesIndex].NumberOfRows);
                transponedMatrix.NumberOfRows.ShouldBe(this.matrices[matricesIndex].NumberOfColumns);

                for (Int32 rowIndex = 0; rowIndex < transponedMatrix.NumberOfRows; rowIndex++)
                {
                    for (Int32 columnIndex = 0; columnIndex < transponedMatrix.NumberOfColumns; columnIndex++)
                    {
                        transponedMatrix[rowIndex, columnIndex].ShouldBe(this.matrices[matricesIndex][columnIndex, rowIndex]);
                    }
                }
            }

            // exceptions
            Should.Throw <ArgumentNullException>(() => MatrixComputations.Transpose((Matrix)null));
        }