From dc7bb4e2c5bcf95e437b4bcc36e71845466de7b2 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 9 Mar 2011 23:58:00 +0200 Subject: [PATCH] Moved methods to a more appropriate place on Complex. --- .../Complex/MatrixTests.Arithmetic.cs | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs index 06b13065..904c530d 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs @@ -624,6 +624,64 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex } } } + + /// + /// Multiply a matrix with incompatible size matrix throws ArgumentException. + /// + [Test] + public void MultiplyMatrixMatrixWithIncompatibleSizesThrowsArgumentException() + { + var matrix = TestMatrices["Singular3x3"]; + var other = TestMatrices["Wide2x3"]; + Assert.Throws(() => { var result = matrix * other; }); + } + + /// + /// Multiply null matrix with matrix throws ArgumentNullException. + /// + [Test] + public void MultiplyNullMatrixWithMatrixThrowsArgumentNullException() + { + Matrix matrix = null; + var other = TestMatrices["Wide2x3"]; + Assert.Throws(() => { var result = matrix * other; }); + } + + /// + /// Multiply a matrix with null matrix throws ArgumentNullException. + /// + [Test] + public void MultiplyMatrixWithNullMatrixThrowsArgumentNullException() + { + var matrix = TestMatrices["Wide2x3"]; + Matrix other = null; + Assert.Throws(() => { var result = matrix * other; }); + } + + /// + /// Can multiply a matrix with matrix into a result matrix. + /// + /// Matrix A name. + /// Matrix B name. + [Test, Sequential] + public virtual void CanMultiplyMatrixWithMatrixIntoResult([Values("Singular3x3", "Singular4x4", "Wide2x3", "Wide2x3", "Tall3x2")] string nameA, [Values("Square3x3", "Square4x4", "Square3x3", "Tall3x2", "Wide2x3")] string nameB) + { + var matrixA = TestMatrices[nameA]; + var matrixB = TestMatrices[nameB]; + var matrixC = CreateMatrix(matrixA.RowCount, matrixB.ColumnCount); + matrixA.Multiply(matrixB, matrixC); + + Assert.AreEqual(matrixC.RowCount, matrixA.RowCount); + Assert.AreEqual(matrixC.ColumnCount, matrixB.ColumnCount); + + for (var i = 0; i < matrixC.RowCount; i++) + { + for (var j = 0; j < matrixC.ColumnCount; j++) + { + AssertHelpers.AlmostEqual(matrixA.Row(i) * matrixB.Column(j), matrixC[i, j], 15); + } + } + } /// /// Can multiply transposed matrix with a vector. @@ -779,64 +837,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex } } - /// - /// Multiply a matrix with incompatible size matrix throws ArgumentException. - /// - [Test] - public void MultiplyMatrixMatrixWithIncompatibleSizesThrowsArgumentException() - { - var matrix = TestMatrices["Singular3x3"]; - var other = TestMatrices["Wide2x3"]; - Assert.Throws(() => { var result = matrix * other; }); - } - - /// - /// Multiply null matrix with matrix throws ArgumentNullException. - /// - [Test] - public void MultiplyNullMatrixWithMatrixThrowsArgumentNullException() - { - Matrix matrix = null; - var other = TestMatrices["Wide2x3"]; - Assert.Throws(() => { var result = matrix * other; }); - } - - /// - /// Multiply a matrix with null matrix throws ArgumentNullException. - /// - [Test] - public void MultiplyMatrixWithNullMatrixThrowsArgumentNullException() - { - var matrix = TestMatrices["Wide2x3"]; - Matrix other = null; - Assert.Throws(() => { var result = matrix * other; }); - } - - /// - /// Can multiply a matrix with matrix into a result matrix. - /// - /// Matrix A name. - /// Matrix B name. - [Test, Sequential] - public virtual void CanMultiplyMatrixWithMatrixIntoResult([Values("Singular3x3", "Singular4x4", "Wide2x3", "Wide2x3", "Tall3x2")] string nameA, [Values("Square3x3", "Square4x4", "Square3x3", "Tall3x2", "Wide2x3")] string nameB) - { - var matrixA = TestMatrices[nameA]; - var matrixB = TestMatrices[nameB]; - var matrixC = CreateMatrix(matrixA.RowCount, matrixB.ColumnCount); - matrixA.Multiply(matrixB, matrixC); - - Assert.AreEqual(matrixC.RowCount, matrixA.RowCount); - Assert.AreEqual(matrixC.ColumnCount, matrixB.ColumnCount); - - for (var i = 0; i < matrixC.RowCount; i++) - { - for (var j = 0; j < matrixC.ColumnCount; j++) - { - AssertHelpers.AlmostEqual(matrixA.Row(i) * matrixB.Column(j), matrixC[i, j], 15); - } - } - } - /// /// Can negate a matrix. ///