From e9d8de063116eb7ff5afb165b9c0c0557ae645fe Mon Sep 17 00:00:00 2001 From: Jurgen Van Gael Date: Wed, 27 Jan 2010 21:10:24 +0800 Subject: [PATCH] Negate unit tests. --- .../Double/MatrixTests.Arithmetic.cs | 73 +++++++++++++++++++ .../LinearAlgebraTests/Double/MatrixTests.cs | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs index 07f35a7b..81ef8ee6 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.Arithmetic.cs @@ -478,5 +478,78 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double } } } + + [Test] + [Row("Singular3x3")] + [Row("Square3x3")] + [Row("Square4x4")] + [Row("Tall3x2")] + [Row("Wide2x3")] + [MultipleAsserts] + public void CanNegate(string name) + { + var matrix = testMatrices[name]; + var copy = matrix.Clone(); + + copy.Negate(); + + for (int i = 0; i < matrix.RowCount; i++) + { + for (int j = 0; j < matrix.ColumnCount; j++) + { + Assert.AreEqual(-matrix[i, j], copy[i, j]); + } + } + } + + [Test] + [Row("Singular3x3")] + [Row("Square3x3")] + [Row("Square4x4")] + [Row("Tall3x2")] + [Row("Wide2x3")] + [MultipleAsserts] + public void CanNegateIntoResult(string name) + { + var matrix = testMatrices[name]; + var copy = matrix.Clone(); + + matrix.Negate(copy); + + for (int i = 0; i < matrix.RowCount; i++) + { + for (int j = 0; j < matrix.ColumnCount; j++) + { + Assert.AreEqual(-matrix[i, j], copy[i, j]); + } + } + } + + [Test] + [ExpectedArgumentNullException] + public void NegateIntoResultFailsWhenResultIsNull() + { + var matrix = testMatrices["Singular3x3"]; + Matrix copy = null; + matrix.Negate(copy); + } + + [Test] + [ExpectedArgumentException] + public void NegateIntoResultFailsWhenResultHasMoreRows() + { + Matrix matrix = testMatrices["Singular3x3"]; + Matrix target = CreateMatrix(matrix.RowCount + 1, matrix.ColumnCount); + matrix.Negate(target); + } + + [Test] + [ExpectedArgumentException] + public void NegateIntoResultFailsWhenResultHasMoreColumns() + { + Matrix matrix = testMatrices["Singular3x3"]; + Matrix target = CreateMatrix(matrix.RowCount + 1, matrix.ColumnCount); + matrix.Negate(target); + } } } \ No newline at end of file diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs index e663fd41..ba37da29 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs @@ -107,7 +107,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double } [Test] - [ExpectedException(typeof(ArgumentNullException))] + [ExpectedArgumentNullException] public void CopyToFailsWhenTargetIsNull() { Matrix matrix = testMatrices["Singular3x3"];