diff --git a/src/UnitTests/LinearAlgebraTests/Complex/DenseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/DenseVectorArithmeticTheory.cs index bd60c3b7..8773971f 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/DenseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/DenseVectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex @@ -43,10 +42,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public class DenseVectorArithmeticTheory : VectorArithmeticTheory { [Datapoints] - Vector[] denseVectors = + TestVector[] _denseVectors = { - Vector.Build.Dense(new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1), new Complex(4, 1), new Complex(5, 1) }), - Vector.Build.Dense(new[] { new Complex(2, -1), new Complex(0, 0), new Complex(0, 2), new Complex(-5, 1), new Complex(0, 0) }) + TestVector.Dense5, + TestVector.Dense5WithZeros }; [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs index 6bb899e0..1019d529 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -42,25 +42,30 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex [TestFixture, Category("LA")] public class MatrixStructureTheory : MatrixStructureTheory { + protected override Matrix GetMatrix(TestMatrix matrix) + { + return TestData.GetMatrix(matrix); + } + [Datapoints] - Matrix[] _matrices = + TestMatrix[] _matrices = { - Matrix.Build.DenseOfArray(new[,] { { 1d, new Complex(1.1d, -4d), 2d }, { 1d, 1d, 2d }, { 1d, new Complex(1d, 2d), 2d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, 1.1d, new Complex(2.2d, -1.2d) }, { -4.4d, 5.5d, 6.6d } }), - Matrix.Build.DenseOfArray(new[,] { { new Complex(-1.1d, -2d), -2.2d, -3.3d, -4.4d }, { 0d, 1.1d, 2.2d, 3.3d }, { 1d, 2.1d, 6.2d, 4.3d }, { -4.4d, 5.5d, 6.6d, -7.7d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, new Complex(-2.2d, 3.4d), -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d }, { Complex.Zero, 1.1d }, { -4.4d, 5.5d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, new Complex(1.1d, 0.1d), 2.2d } }), - Matrix.Build.DenseOfArray(new[,] { { 1d, 2d, 3d }, { 2d, new Complex(2d, 2d), 0d }, { 3d, Complex.Zero, 3d } }), + TestMatrix.DenseSquare3x3, + TestMatrix.DenseSquare3x3b, + TestMatrix.DenseSquare4x4, + TestMatrix.DenseSquare4x4b, + TestMatrix.DenseTall3x2, + TestMatrix.DenseWide2x3, + TestMatrix.DenseSquare3x3c, - Matrix.Build.SparseOfArray(new[,] { { 7d, 1d, 2d }, { 1d, 1d, 2d }, { 1d, 1d + Complex.ImaginaryOne, 2d } }), - Matrix.Build.SparseOfArray(new[,] { { 7d, 1d, 2d }, { new Complex(1d, 2d), 0d, Complex.Zero }, { -2d, 0d, 0d } }), - Matrix.Build.SparseOfArray(new[,] { { -1.1d, 0d, 0d }, { 0d, new Complex(1.1d, 2d), 2.2d } }), + TestMatrix.SparseSquare3x3, + TestMatrix.SparseSquare3x3b, + TestMatrix.SparseWide2x3, - Matrix.Build.Diagonal(3, 3, new[] { new Complex(1d, 1d), -2d, 1.5d }), - Matrix.Build.Diagonal(3, 3, new[] { new Complex(1d, 2d), 0d, -1.5d }), + TestMatrix.DiagonalSquare3x3, + TestMatrix.DiagonalSquare3x3b, - new UserDefinedMatrix(new[,] { { 0d, 1d, 2d }, { -1d, 7.7d, 0d }, { -2d, Complex.Zero, 0d } }) + TestMatrix.UserSquare3x3 }; [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Complex/SparseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/SparseVectorArithmeticTheory.cs index 3044103e..175a5a4a 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/SparseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/SparseVectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex @@ -43,15 +42,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public class SparseVectorArithmeticTheory : VectorArithmeticTheory { [Datapoints] - Vector[] denseVectors = + TestVector[] _sparseVectors = { - Vector.Build.SparseOfEnumerable(new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1), new Complex(4, 1), new Complex(5, 1) }), - Vector.Build.SparseOfEnumerable(new[] { new Complex(2, -1), new Complex(0, 0), new Complex(0, 2), new Complex(-5, 1), new Complex(0, 0) }), - Vector.Build.Sparse(5), - Vector.Build.Sparse(int.MaxValue) + TestVector.Sparse5, + TestVector.Sparse5WithZeros, + TestVector.Sparse5AllZeros, + TestVector.SparseMaxLengthAllZeros }; [Datapoints] - Complex[] scalars = { new Complex(2d, -1d) }; + Complex[] _scalars = { new Complex(2d, -1d) }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex/TestData.cs b/src/UnitTests/LinearAlgebraTests/Complex/TestData.cs new file mode 100644 index 00000000..fe2e826a --- /dev/null +++ b/src/UnitTests/LinearAlgebraTests/Complex/TestData.cs @@ -0,0 +1,87 @@ +// +// Math.NET Numerics, part of the Math.NET Project +// http://numerics.mathdotnet.com +// http://github.com/mathnet/mathnet-numerics +// http://mathnetnumerics.codeplex.com +// +// Copyright (c) 2009-2015 Math.NET +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using MathNet.Numerics.LinearAlgebra; + +namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex +{ +#if NOSYSNUMERICS + using Complex = Numerics.Complex; +#else + using Complex = System.Numerics.Complex; +#endif + + public static class TestData + { + static readonly MatrixBuilder M = Matrix.Build; + static readonly VectorBuilder V = Vector.Build; + + public static Matrix GetMatrix(TestMatrix matrix) + { + switch (matrix) + { + case TestMatrix.DenseSquare3x3: return M.DenseOfArray(new[,] { { 1d, new Complex(1.1d, -4d), 2d }, { 1d, 1d, 2d }, { 1d, new Complex(1d, 2d), 2d } }); + case TestMatrix.DenseSquare3x3b: return M.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, 1.1d, new Complex(2.2d, -1.2d) }, { -4.4d, 5.5d, 6.6d } }); + case TestMatrix.DenseSquare3x3c: return M.DenseOfArray(new[,] { { 1d, 2d, 3d }, { 2d, new Complex(2d, 2d), 0d }, { 3d, Complex.Zero, 3d } }); + case TestMatrix.DenseSquare4x4: return M.DenseOfArray(new[,] { { new Complex(-1.1d, -2d), -2.2d, -3.3d, -4.4d }, { 0d, 1.1d, 2.2d, 3.3d }, { 1d, 2.1d, 6.2d, 4.3d }, { -4.4d, 5.5d, 6.6d, -7.7d } }); + case TestMatrix.DenseSquare4x4b: return M.DenseOfArray(new[,] { { -1.1d, new Complex(-2.2d, 3.4d), -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d } }); + case TestMatrix.DenseTall3x2: return M.DenseOfArray(new[,] { { -1.1d, -2.2d }, { Complex.Zero, 1.1d }, { -4.4d, 5.5d } }); + case TestMatrix.DenseWide2x3: return M.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, new Complex(1.1d, 0.1d), 2.2d } }); + + case TestMatrix.SparseSquare3x3: return M.SparseOfArray(new[,] { { 7d, 1d, 2d }, { 1d, 1d, 2d }, { 1d, 1d + Complex.ImaginaryOne, 2d } }); + case TestMatrix.SparseSquare3x3b: return M.SparseOfArray(new[,] { { 7d, 1d, 2d }, { new Complex(1d, 2d), 0d, Complex.Zero }, { -2d, 0d, 0d } }); + case TestMatrix.SparseWide2x3: return M.SparseOfArray(new[,] { { -1.1d, 0d, 0d }, { 0d, new Complex(1.1d, 2d), 2.2d } }); + + case TestMatrix.DiagonalSquare3x3: return M.Diagonal(3, 3, new[] { new Complex(1d, 1d), -2d, 1.5d }); + case TestMatrix.DiagonalSquare3x3b: return M.Diagonal(3, 3, new[] { new Complex(1d, 2d), 0d, -1.5d }); + + case TestMatrix.UserSquare3x3: return new UserDefinedMatrix(new[,] { { 0d, 1d, 2d }, { -1d, 7.7d, 0d }, { -2d, Complex.Zero, 0d } }); + default: throw new NotSupportedException(); + } + } + + public static Vector GetVector(TestVector vector) + { + switch (vector) + { + case TestVector.Dense5: return V.Dense(new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1), new Complex(4, 1), new Complex(5, 1) }); + case TestVector.Dense5WithZeros: return V.Dense(new[] { new Complex(2, -1), new Complex(0, 0), new Complex(0, 2), new Complex(-5, 1), new Complex(0, 0) }); + + case TestVector.Sparse5: return V.SparseOfEnumerable(new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1), new Complex(4, 1), new Complex(5, 1) }); + case TestVector.Sparse5WithZeros: return V.SparseOfEnumerable(new[] { new Complex(2, -1), new Complex(0, 0), new Complex(0, 2), new Complex(-5, 1), new Complex(0, 0) }); + case TestVector.Sparse5AllZeros: return V.Sparse(5); + case TestVector.SparseMaxLengthAllZeros: return V.Sparse(int.MaxValue); + + default: throw new NotSupportedException(); + } + } + } +} diff --git a/src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs index 6f705400..daabc71b 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,6 +28,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex @@ -41,6 +42,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex [TestFixture, Category("LA")] public abstract class VectorArithmeticTheory : VectorArithmeticTheory { + protected override Vector GetVector(TestVector vector) + { + return TestData.GetVector(vector); + } + protected override Complex Minus(Complex value) { return -value; } protected override Complex Add(Complex first, Complex second) { return first + second; } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorArithmeticTheory.cs index f81f4bac..9f9bb3be 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/DenseVectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,24 +28,21 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 { - using Numerics; - [TestFixture, Category("LA")] public class DenseVectorArithmeticTheory : VectorArithmeticTheory { [Datapoints] - Vector[] denseVectors = + TestVector[] _denseVectors = { - Vector.Build.Dense(new[] { new Complex32(1, 1), new Complex32(2, 1), new Complex32(3, 1), new Complex32(4, 1), new Complex32(5, 1) }), - Vector.Build.Dense(new[] { new Complex32(2, -1), new Complex32(0, 0), new Complex32(0, 2), new Complex32(-5, 1), new Complex32(0, 0) }) + TestVector.Dense5, + TestVector.Dense5WithZeros }; [Datapoints] - Complex32[] scalars = { new Complex32(2f, -1f) }; + Numerics.Complex32[] _scalars = { new Numerics.Complex32(2f, -1f) }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs index 2061c793..9778f5d8 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -38,28 +38,33 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 [TestFixture, Category("LA")] public class MatrixStructureTheory : MatrixStructureTheory { + protected override Matrix GetMatrix(TestMatrix matrix) + { + return TestData.GetMatrix(matrix); + } + [Datapoints] - Matrix[] _matrices = + TestMatrix[] _matrices = { - Matrix.Build.DenseOfArray(new[,] { { 1f, new Complex32(1.1f, -4f), 2f }, { 1f, 1f, 2f }, { 1f, new Complex32(1f, 2f), 2f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, 1.1f, new Complex32(2.2f, -1.2f) }, { -4.4f, 5.5f, 6.6f } }), - Matrix.Build.DenseOfArray(new[,] { { new Complex32(-1.1f, -2f), -2.2f, -3.3f, -4.4f }, { 0f, 1.1f, 2.2f, 3.3f }, { 1f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, new Complex32(-2.2f, 3.4f), -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f }, { Complex32.Zero, 1.1f }, { -4.4f, 5.5f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, new Complex32(1.1f, 0.1f), 2.2f } }), - Matrix.Build.DenseOfArray(new[,] { { 1f, 2f, 3f }, { 2f, new Complex32(2f, 2f), 0f }, { 3f, Complex32.Zero, 3f } }), + TestMatrix.DenseSquare3x3, + TestMatrix.DenseSquare3x3b, + TestMatrix.DenseSquare4x4, + TestMatrix.DenseSquare4x4b, + TestMatrix.DenseTall3x2, + TestMatrix.DenseWide2x3, + TestMatrix.DenseSquare3x3c, - Matrix.Build.SparseOfArray(new[,] { { 7f, 1f, 2f }, { 1f, 1f, 2f }, { 1f, 1f + Complex32.ImaginaryOne, 2f } }), - Matrix.Build.SparseOfArray(new[,] { { 7f, 1f, 2f }, { new Complex32(1f, 2f), 0f, Complex32.Zero }, { -2f, 0f, 0f } }), - Matrix.Build.SparseOfArray(new[,] { { -1.1f, 0f, 0f }, { 0f, new Complex32(1.1f, 2f), 2.2f } }), + TestMatrix.SparseSquare3x3, + TestMatrix.SparseSquare3x3b, + TestMatrix.SparseWide2x3, - Matrix.Build.Diagonal(3, 3, new[] { new Complex32(1f, 1f), -2f, 1.5f }), - Matrix.Build.Diagonal(3, 3, new[] { new Complex32(1f, 2f), 0f, -1.5f }), + TestMatrix.DiagonalSquare3x3, + TestMatrix.DiagonalSquare3x3b, - new UserDefinedMatrix(new[,] { { 0f, 1f, 2f }, { -1f, 7.7f, 0f }, { -2f, Complex32.Zero, 0f } }) + TestMatrix.UserSquare3x3 }; [Datapoints] - Complex32[] scalars = { new Complex32(2f, 0f), new Complex32(-1.5f, 3.5f), Complex32.Zero }; + Complex32[] _scalars = { new Complex32(2f, 0f), new Complex32(-1.5f, 3.5f), Complex32.Zero }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorArithmeticTheory.cs index e636e4ac..8d7c0c0a 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 @@ -39,15 +38,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public class SparseVectorArithmeticTheory : VectorArithmeticTheory { [Datapoints] - Vector[] denseVectors = + TestVector[] _sparseVectors = { - Vector.Build.SparseOfEnumerable(new[] { new Complex32(1, 1), new Complex32(2, 1), new Complex32(3, 1), new Complex32(4, 1), new Complex32(5, 1) }), - Vector.Build.SparseOfEnumerable(new[] { new Complex32(2, -1), new Complex32(0, 0), new Complex32(0, 2), new Complex32(-5, 1), new Complex32(0, 0) }), - Vector.Build.Sparse(5), - Vector.Build.Sparse(int.MaxValue) + TestVector.Sparse5, + TestVector.Sparse5WithZeros, + TestVector.Sparse5AllZeros, + TestVector.SparseMaxLengthAllZeros }; [Datapoints] - Complex32[] scalars = { new Complex32(2f, -1f) }; + Complex32[] _scalars = { new Complex32(2f, -1f) }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs b/src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs new file mode 100644 index 00000000..ef4ca885 --- /dev/null +++ b/src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs @@ -0,0 +1,84 @@ +// +// Math.NET Numerics, part of the Math.NET Project +// http://numerics.mathdotnet.com +// http://github.com/mathnet/mathnet-numerics +// http://mathnetnumerics.codeplex.com +// +// Copyright (c) 2009-2015 Math.NET +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using MathNet.Numerics.LinearAlgebra; + +namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 +{ + using Numerics; + + public static class TestData + { + static readonly MatrixBuilder M = Matrix.Build; + static readonly VectorBuilder V = Vector.Build; + + public static Matrix GetMatrix(TestMatrix matrix) + { + switch (matrix) + { + case TestMatrix.DenseSquare3x3: return M.DenseOfArray(new[,] { { 1f, new Complex32(1.1f, -4f), 2f }, { 1f, 1f, 2f }, { 1f, new Complex32(1f, 2f), 2f } }); + case TestMatrix.DenseSquare3x3b: return M.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, 1.1f, new Complex32(2.2f, -1.2f) }, { -4.4f, 5.5f, 6.6f } }); + case TestMatrix.DenseSquare3x3c: return M.DenseOfArray(new[,] { { 1f, 2f, 3f }, { 2f, new Complex32(2f, 2f), 0f }, { 3f, Complex32.Zero, 3f } }); + case TestMatrix.DenseSquare4x4: return M.DenseOfArray(new[,] { { new Complex32(-1.1f, -2f), -2.2f, -3.3f, -4.4f }, { 0f, 1.1f, 2.2f, 3.3f }, { 1f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }); + case TestMatrix.DenseSquare4x4b: return M.DenseOfArray(new[,] { { -1.1f, new Complex32(-2.2f, 3.4f), -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }); + case TestMatrix.DenseTall3x2: return M.DenseOfArray(new[,] { { -1.1f, -2.2f }, { Complex32.Zero, 1.1f }, { -4.4f, 5.5f } }); + case TestMatrix.DenseWide2x3: return M.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, new Complex32(1.1f, 0.1f), 2.2f } }); + + case TestMatrix.SparseSquare3x3: return M.SparseOfArray(new[,] { { 7f, 1f, 2f }, { 1f, 1f, 2f }, { 1f, 1f + Complex32.ImaginaryOne, 2f } }); + case TestMatrix.SparseSquare3x3b: return M.SparseOfArray(new[,] { { 7f, 1f, 2f }, { new Complex32(1f, 2f), 0f, Complex32.Zero }, { -2f, 0f, 0f } }); + case TestMatrix.SparseWide2x3: return M.SparseOfArray(new[,] { { -1.1f, 0f, 0f }, { 0f, new Complex32(1.1f, 2f), 2.2f } }); + + case TestMatrix.DiagonalSquare3x3: return M.Diagonal(3, 3, new[] { new Complex32(1f, 1f), -2f, 1.5f }); + case TestMatrix.DiagonalSquare3x3b: return M.Diagonal(3, 3, new[] { new Complex32(1f, 2f), 0f, -1.5f }); + + case TestMatrix.UserSquare3x3: return new UserDefinedMatrix(new[,] { { 0f, 1f, 2f }, { -1f, 7.7f, 0f }, { -2f, Complex32.Zero, 0f } }); + + default: throw new NotSupportedException(); + } + } + + public static Vector GetVector(TestVector vector) + { + switch (vector) + { + case TestVector.Dense5: return V.Dense(new[] { new Complex32(1, 1), new Complex32(2, 1), new Complex32(3, 1), new Complex32(4, 1), new Complex32(5, 1) }); + case TestVector.Dense5WithZeros: return V.Dense(new[] { new Complex32(2, -1), new Complex32(0, 0), new Complex32(0, 2), new Complex32(-5, 1), new Complex32(0, 0) }); + + case TestVector.Sparse5: return V.SparseOfEnumerable(new[] { new Complex32(1, 1), new Complex32(2, 1), new Complex32(3, 1), new Complex32(4, 1), new Complex32(5, 1) }); + case TestVector.Sparse5WithZeros: return V.SparseOfEnumerable(new[] { new Complex32(2, -1), new Complex32(0, 0), new Complex32(0, 2), new Complex32(-5, 1), new Complex32(0, 0) }); + case TestVector.Sparse5AllZeros: return V.Sparse(5); + case TestVector.SparseMaxLengthAllZeros: return V.Sparse(int.MaxValue); + + default: throw new NotSupportedException(); + } + } + } +} diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs index 6170d13d..45e0fa6e 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,14 +28,21 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.LinearAlgebra; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 { using Numerics; - using NUnit.Framework; [TestFixture, Category("LA")] public abstract class VectorArithmeticTheory : VectorArithmeticTheory { + protected override Vector GetVector(TestVector vector) + { + return TestData.GetVector(vector); + } + protected override Complex32 Minus(Complex32 value) { return -value; } protected override Complex32 Add(Complex32 first, Complex32 second) { return first + second; } } diff --git a/src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs index 8a928f86..6ae68e77 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/DenseVectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double @@ -37,13 +36,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public class DenseVectorArithmeticTheory : VectorArithmeticTheory { [Datapoints] - Vector[] denseVectors = + TestVector[] _denseVectors = { - Vector.Build.Dense(new double[] { 1, 2, 3, 4, 5 }), - Vector.Build.Dense(new double[] { 2, 0, 0, -5, 0 }) + TestVector.Dense5, + TestVector.Dense5WithZeros }; [Datapoints] - double[] scalars = { 2d }; + double[] _scalars = { 2d }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs index 5238d16e..3dde825a 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -36,25 +36,30 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double [TestFixture, Category("LA")] public class MatrixStructureTheory : MatrixStructureTheory { + protected override Matrix GetMatrix(TestMatrix matrix) + { + return TestData.GetMatrix(matrix); + } + [Datapoints] - Matrix[] _matrices = + TestMatrix[] _matrices = { - Matrix.Build.DenseOfArray(new[,] { { 1d, 1d, 2d }, { 1d, 1d, 2d }, { 1d, 1d, 2d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, 1.1d, 2.2d }, { -4.4d, 5.5d, 6.6d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d, -4.4d }, { 0d, 1.1d, 2.2d, 3.3d }, { 1d, 2.1d, 6.2d, 4.3d }, { -4.4d, 5.5d, 6.6d, -7.7d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d }, { 0d, 1.1d }, { -4.4d, 5.5d } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, 1.1d, 2.2d } }), - Matrix.Build.DenseOfArray(new[,] { { 1d, 2d, 3d }, { 2d, 2d, 0d }, { 3d, 0d, 3d } }), + TestMatrix.DenseSquare3x3, + TestMatrix.DenseSquare3x3b, + TestMatrix.DenseSquare4x4, + TestMatrix.DenseSquare4x4b, + TestMatrix.DenseTall3x2, + TestMatrix.DenseWide2x3, + TestMatrix.DenseSquare3x3c, - Matrix.Build.SparseOfArray(new[,] { { 7d, 1d, 2d }, { 1d, 1d, 2d }, { 1d, 1d, 2d } }), - Matrix.Build.SparseOfArray(new[,] { { 7d, 1d, 2d }, { 1d, 0d, 0d }, { -2d, 0d, 0d } }), - Matrix.Build.SparseOfArray(new[,] { { -1.1d, 0d, 0d }, { 0d, 1.1d, 2.2d } }), + TestMatrix.SparseSquare3x3, + TestMatrix.SparseSquare3x3b, + TestMatrix.SparseWide2x3, - Matrix.Build.Diagonal(3, 3, new[] { 1d, -2d, 1.5d }), - Matrix.Build.Diagonal(3, 3, new[] { 1d, 0d, -1.5d }), + TestMatrix.DiagonalSquare3x3, + TestMatrix.DiagonalSquare3x3b, - new UserDefinedMatrix(new[,] { { 0d, 1d, 2d }, { -1d, 7.7d, 0d }, { -2d, 0d, 0d } }) + TestMatrix.UserSquare3x3 }; [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Double/SparseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/SparseVectorArithmeticTheory.cs index cba5dd56..1eae0640 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/SparseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/SparseVectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double @@ -37,15 +36,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public class SparseVectorArithmeticTheory : VectorArithmeticTheory { [Datapoints] - Vector[] denseVectors = + TestVector[] _sparseVectors = { - Vector.Build.SparseOfEnumerable(new double[] { 1, 2, 3, 4, 5 }), - Vector.Build.SparseOfEnumerable(new double[] { 2, 0, 0, -5, 0 }), - Vector.Build.Sparse(5), - Vector.Build.Sparse(int.MaxValue) + TestVector.Sparse5, + TestVector.Sparse5WithZeros, + TestVector.Sparse5AllZeros, + TestVector.SparseMaxLengthAllZeros }; [Datapoints] - double[] scalars = { 2d }; + double[] _scalars = { 2d }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Double/TestData.cs b/src/UnitTests/LinearAlgebraTests/Double/TestData.cs new file mode 100644 index 00000000..4a406451 --- /dev/null +++ b/src/UnitTests/LinearAlgebraTests/Double/TestData.cs @@ -0,0 +1,82 @@ +// +// Math.NET Numerics, part of the Math.NET Project +// http://numerics.mathdotnet.com +// http://github.com/mathnet/mathnet-numerics +// http://mathnetnumerics.codeplex.com +// +// Copyright (c) 2009-2015 Math.NET +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using MathNet.Numerics.LinearAlgebra; + +namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double +{ + public static class TestData + { + static readonly MatrixBuilder M = Matrix.Build; + static readonly VectorBuilder V = Vector.Build; + + public static Matrix GetMatrix(TestMatrix matrix) + { + switch (matrix) + { + case TestMatrix.DenseSquare3x3: return M.DenseOfArray(new[,] { { 1d, 1d, 2d }, { 1d, 1d, 2d }, { 1d, 1d, 2d } }); + case TestMatrix.DenseSquare3x3b: return M.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, 1.1d, 2.2d }, { -4.4d, 5.5d, 6.6d } }); + case TestMatrix.DenseSquare3x3c: return M.DenseOfArray(new[,] { { 1d, 2d, 3d }, { 2d, 2d, 0d }, { 3d, 0d, 3d } }); + case TestMatrix.DenseSquare4x4: return M.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d, -4.4d }, { 0d, 1.1d, 2.2d, 3.3d }, { 1d, 2.1d, 6.2d, 4.3d }, { -4.4d, 5.5d, 6.6d, -7.7d } }); + case TestMatrix.DenseSquare4x4b: return M.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d }, { -1.1d, -2.2d, -3.3d, -4.4d } }); + case TestMatrix.DenseTall3x2: return M.DenseOfArray(new[,] { { -1.1d, -2.2d }, { 0d, 1.1d }, { -4.4d, 5.5d } }); + case TestMatrix.DenseWide2x3: return M.DenseOfArray(new[,] { { -1.1d, -2.2d, -3.3d }, { 0d, 1.1d, 2.2d } }); + + case TestMatrix.SparseSquare3x3: return M.SparseOfArray(new[,] { { 7d, 1d, 2d }, { 1d, 1d, 2d }, { 1d, 1d, 2d } }); + case TestMatrix.SparseSquare3x3b: return M.SparseOfArray(new[,] { { 7d, 1d, 2d }, { 1d, 0d, 0d }, { -2d, 0d, 0d } }); + case TestMatrix.SparseWide2x3: return M.SparseOfArray(new[,] { { -1.1d, 0d, 0d }, { 0d, 1.1d, 2.2d } }); + + case TestMatrix.DiagonalSquare3x3: return M.Diagonal(3, 3, new[] { 1d, -2d, 1.5d }); + case TestMatrix.DiagonalSquare3x3b: return M.Diagonal(3, 3, new[] { 1d, 0d, -1.5d }); + + case TestMatrix.UserSquare3x3: return new UserDefinedMatrix(new[,] { { 0d, 1d, 2d }, { -1d, 7.7d, 0d }, { -2d, 0d, 0d } }); + + default: throw new NotSupportedException(); + } + } + + public static Vector GetVector(TestVector vector) + { + switch (vector) + { + case TestVector.Dense5: return V.Dense(new double[] { 1, 2, 3, 4, 5 }); + case TestVector.Dense5WithZeros: return V.Dense(new double[] { 2, 0, 0, -5, 0 }); + + case TestVector.Sparse5: return V.SparseOfEnumerable(new double[] { 1, 2, 3, 4, 5 }); + case TestVector.Sparse5WithZeros: return V.SparseOfEnumerable(new double[] { 2, 0, 0, -5, 0 }); + case TestVector.Sparse5AllZeros: return V.Sparse(5); + case TestVector.SparseMaxLengthAllZeros: return V.Sparse(int.MaxValue); + + default: throw new NotSupportedException(); + } + } + } +} diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs index 4ab0c3d5..a11b3557 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,13 +28,19 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.LinearAlgebra; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double { - using NUnit.Framework; - [TestFixture, Category("LA")] public abstract class VectorArithmeticTheory : VectorArithmeticTheory { + protected override Vector GetVector(TestVector vector) + { + return TestData.GetVector(vector); + } + protected override double Minus(double value) { return -value; } protected override double Add(double first, double second) { return first + second; } } diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs index 5cfe957b..63af3fe5 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs @@ -37,8 +37,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests partial class MatrixStructureTheory { [Theory] - public void CanGetFieldsByIndex(Matrix matrix) + public void CanGetFieldsByIndex(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + Assert.That(() => matrix[0, 0], Throws.Nothing); Assert.That(() => matrix[0, matrix.ColumnCount - 1], Throws.Nothing); Assert.That(() => matrix[matrix.RowCount - 1, 0], Throws.Nothing); @@ -49,8 +51,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetRow(Matrix matrix) + public void CanGetRow(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // First Row var firstrow = matrix.Row(0); Assert.That(firstrow.Count, Is.EqualTo(matrix.ColumnCount)); @@ -73,8 +77,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetRowIntoResult(Matrix matrix) + public void CanGetRowIntoResult(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var row = Vector.Build.Dense(matrix.ColumnCount); matrix.Row(0, row); @@ -89,8 +95,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetRowWithRange(Matrix matrix) + public void CanGetRowWithRange(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // First Row, Columns 0..1 var firstrow = matrix.Row(0, 0, 2); Assert.That(firstrow.Count, Is.EqualTo(2)); @@ -124,8 +132,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetRowWithRangeIntoResult(Matrix matrix) + public void CanGetRowWithRangeIntoResult(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var row = Vector.Build.Dense(matrix.ColumnCount - 1); matrix.Row(0, 1, matrix.ColumnCount - 1, row); @@ -141,8 +151,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetColumn(Matrix matrix) + public void CanGetColumn(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // First Column var firstcol = matrix.Column(0); Assert.That(firstcol.Count, Is.EqualTo(matrix.RowCount)); @@ -165,8 +177,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetColumnIntoResult(Matrix matrix) + public void CanGetColumnIntoResult(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var col = Vector.Build.Dense(matrix.RowCount); matrix.Column(0, col); @@ -181,8 +195,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetColumnWithRange(Matrix matrix) + public void CanGetColumnWithRange(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // First Column, Rows 0..1 var firstcol = matrix.Column(0, 0, 2); Assert.That(firstcol.Count, Is.EqualTo(2)); @@ -216,8 +232,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetColumnWithRangeIntoResult(Matrix matrix) + public void CanGetColumnWithRangeIntoResult(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var col = Vector.Build.Dense(matrix.RowCount - 1); matrix.Column(0, 1, matrix.RowCount - 1, col); @@ -233,8 +251,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanSetRow(Matrix matrix) + public void CanSetRow(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // First Row var m = matrix.Clone(); var v = CreateVectorFor(m, matrix.ColumnCount); @@ -268,8 +288,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanSetRowArray(Matrix matrix) + public void CanSetRowArray(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // First Row var m = matrix.Clone(); m.SetRow(0, Vector.Build.Dense(matrix.ColumnCount).ToArray()); @@ -301,8 +323,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanSetColumn(Matrix matrix) + public void CanSetColumn(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // First Column var m = matrix.Clone(); var v = CreateVectorFor(m, matrix.RowCount); @@ -336,8 +360,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanSetColumnArray(Matrix matrix) + public void CanSetColumnArray(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // First Column var m = matrix.Clone(); m.SetColumn(0, Vector.Build.Dense(matrix.RowCount).ToArray()); @@ -369,8 +395,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetUpperTriangle(Matrix matrix) + public void CanGetUpperTriangle(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var upper = matrix.UpperTriangle(); for (var i = 0; i < matrix.RowCount; i++) { @@ -382,8 +410,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetUpperTriangleIntoResult(Matrix matrix) + public void CanGetUpperTriangleIntoResult(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.UpperTriangle(dense); for (var i = 0; i < matrix.RowCount; i++) @@ -410,8 +440,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetLowerTriangle(Matrix matrix) + public void CanGetLowerTriangle(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var upper = matrix.LowerTriangle(); for (var i = 0; i < matrix.RowCount; i++) { @@ -423,8 +455,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetLowerTriangleIntoResult(Matrix matrix) + public void CanGetLowerTriangleIntoResult(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.LowerTriangle(dense); for (var i = 0; i < matrix.RowCount; i++) @@ -451,8 +485,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetStrictlyUpperTriangle(Matrix matrix) + public void CanGetStrictlyUpperTriangle(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var upper = matrix.StrictlyUpperTriangle(); for (var i = 0; i < matrix.RowCount; i++) { @@ -464,8 +500,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetStrictlyUpperTriangleIntoResult(Matrix matrix) + public void CanGetStrictlyUpperTriangleIntoResult(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.StrictlyUpperTriangle(dense); for (var i = 0; i < matrix.RowCount; i++) @@ -492,8 +530,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetStrictlyLowerTriangle(Matrix matrix) + public void CanGetStrictlyLowerTriangle(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var upper = matrix.StrictlyLowerTriangle(); for (var i = 0; i < matrix.RowCount; i++) { @@ -505,8 +545,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetStrictlyLowerTriangleIntoResult(Matrix matrix) + public void CanGetStrictlyLowerTriangleIntoResult(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.StrictlyLowerTriangle(dense); for (var i = 0; i < matrix.RowCount; i++) @@ -533,8 +575,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetDiagonal(Matrix matrix) + public void CanGetDiagonal(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var diag = matrix.Diagonal(); Assert.That(diag.Count, Is.EqualTo(Math.Min(matrix.RowCount, matrix.ColumnCount))); for (var i = 0; i < Math.Min(matrix.RowCount, matrix.ColumnCount); i++) @@ -544,8 +588,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanSetDiagonal(Matrix matrix) + public void CanSetDiagonal(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var m = matrix.Clone(); var v = CreateVectorFor(m, Math.Min(matrix.RowCount, matrix.ColumnCount)); m.SetDiagonal(v); @@ -564,8 +610,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanSetDiagonalArray(Matrix matrix) + public void CanSetDiagonalArray(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var m = matrix.Clone(); m.SetDiagonal(new T[Math.Min(matrix.RowCount, matrix.ColumnCount)]); for (var i = 0; i < matrix.RowCount; i++) @@ -583,8 +631,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetSubmatrix(Matrix matrix) + public void CanGetSubmatrix(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // Top Left Corner 2x2 var topleft = matrix.SubMatrix(0, 2, 0, 2); Assert.That(topleft.RowCount, Is.EqualTo(2)); @@ -625,8 +675,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanSetSubmatrix(Matrix matrix) + public void CanSetSubmatrix(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // Top Left Corner 2x2 var topleft = CreateDenseFor(matrix, 2, 2); var m = matrix.Clone(); @@ -658,7 +710,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests Assert.That(() => m.SetSubMatrix(matrix.RowCount, 1, 0, 1, Matrix.Build.Dense(1, 1)), Throws.InstanceOf()); Assert.That(() => m.SetSubMatrix(0, 1, -1, 1, Matrix.Build.Dense(1, 1)), Throws.InstanceOf()); Assert.That(() => m.SetSubMatrix(0, 1, matrix.ColumnCount, 1, Matrix.Build.Dense(1, 1)), Throws.InstanceOf()); - + // Usually invalid, but not for SetSubMatrix (since size is explicitly provided) Assert.That(() => m.SetSubMatrix(0, 1, 0, 1, Matrix.Build.Dense(1, 2)), Throws.Nothing); Assert.That(() => m.SetSubMatrix(0, 1, 0, 1, Matrix.Build.Dense(2, 1)), Throws.Nothing); diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs index c39cab41..bd1b133e 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs @@ -37,8 +37,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests partial class MatrixStructureTheory { [Theory] - public void CanMap(Matrix matrix) + public void CanMap(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); Matrix a = matrix.Map(x => x, Zeros.AllowSkip); Assert.That(a, Is.EqualTo(matrix)); Assert.That(a.Storage.IsDense, Is.EqualTo(matrix.Storage.IsDense)); @@ -65,8 +66,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanMapIndexed(Matrix matrix) + public void CanMapIndexed(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); Matrix a = matrix.MapIndexed((i, j, x) => { if (i != 0 || j != 1) Assert.That(matrix.At(i, j), Is.EqualTo(x)); @@ -101,8 +103,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanMapInplace(Matrix matrix) + public void CanMapInplace(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var a = matrix.Clone(); a.MapInplace(x => x, Zeros.AllowSkip); Assert.That(a, Is.EqualTo(matrix)); @@ -119,8 +122,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanMapIndexedInplace(Matrix matrix) + public void CanMapIndexedInplace(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var a = matrix.Clone(); a.MapIndexedInplace((i, j, x) => { @@ -146,8 +150,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanMapSubMatrixToSame(Matrix matrix) + public void CanMapSubMatrixToSame(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); T one = Matrix.Build.One; // Full Range - not forced @@ -169,8 +174,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanMapSubMatrixToDense(Matrix matrix) + public void CanMapSubMatrixToDense(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); T one = Matrix.Build.One; // Full Range - not forced @@ -209,8 +215,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanMapSubMatrixToSparse(Matrix matrix) + public void CanMapSubMatrixToSparse(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); T one = Matrix.Build.One; // Full Range - filled, not forced @@ -258,8 +265,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanFoldRows(Matrix matrix) + public void CanFoldRows(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // not forced T[] rowSum = matrix.FoldByRow((s, x) => Operator.Add(s, x), Operator.Zero, Zeros.AllowSkip); for (int i = 0; i < rowSum.Length; i++) @@ -279,8 +288,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanFoldColumns(Matrix matrix) + public void CanFoldColumns(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + // not forced T[] colSum = matrix.FoldByColumn((s, x) => Operator.Add(s, x), Operator.Zero, Zeros.AllowSkip); for (int i = 0; i < colSum.Length; i++) @@ -300,8 +311,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanFold2(Matrix matrix) + public void CanFold2(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); + var other = -matrix; other.Multiply(Operator.Convert(2), other); diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs index 0405dc91..d68d6801 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs @@ -38,8 +38,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests partial class MatrixStructureTheory { [Theory] - public void CanPermuteRows(Matrix matrix) + public void CanPermuteRows(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var m = matrix.Clone(); var rnd = new System.Random(0); var permutation = new Permutation(Enumerable.Range(0, matrix.RowCount).OrderBy(i => rnd.Next()).ToArray()); @@ -67,8 +68,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanPermuteColumns(Matrix matrix) + public void CanPermuteColumns(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var m = matrix.Clone(); var rnd = new System.Random(0); var permutation = new Permutation(Enumerable.Range(0, matrix.ColumnCount).OrderBy(i => rnd.Next()).ToArray()); @@ -96,8 +98,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanInsertRow(Matrix matrix) + public void CanInsertRow(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var row = Vector.Build.Random(matrix.ColumnCount, 0); for (var position = 0; position < matrix.RowCount + 1; position++) { @@ -132,8 +135,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanRemoveRow(Matrix matrix) + public void CanRemoveRow(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); for (var position = 0; position < matrix.RowCount; position++) { var result = matrix.RemoveRow(position); @@ -156,8 +160,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanInsertColumn(Matrix matrix) + public void CanInsertColumn(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var column = Vector.Build.Random(matrix.RowCount, 0); for (var position = 0; position < matrix.ColumnCount + 1; position++) { @@ -192,8 +197,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanRemoveColumn(Matrix matrix) + public void CanRemoveColumn(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); for (var position = 0; position < matrix.ColumnCount; position++) { var result = matrix.RemoveColumn(position); @@ -217,8 +223,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanAppend(Matrix left, Matrix right) + public void CanAppend(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix) { + Matrix left = GetMatrix(leftTestMatrix); + Matrix right = GetMatrix(rightTestMatrix); + // IF Assume.That(left.RowCount, Is.EqualTo(right.RowCount)); @@ -239,8 +248,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanAppendIntoResult(Matrix left, Matrix right) + public void CanAppendIntoResult(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix) { + Matrix left = GetMatrix(leftTestMatrix); + Matrix right = GetMatrix(rightTestMatrix); + // IF Assume.That(left.RowCount, Is.EqualTo(right.RowCount)); @@ -266,8 +278,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanStack(Matrix top, Matrix bottom) + public void CanStack(TestMatrix topTestMatrix, TestMatrix bottomTestMatrix) { + Matrix top = GetMatrix(topTestMatrix); + Matrix bottom = GetMatrix(bottomTestMatrix); + // IF Assume.That(top.ColumnCount, Is.EqualTo(bottom.ColumnCount)); @@ -288,8 +303,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanStackIntoResult(Matrix top, Matrix bottom) + public void CanStackIntoResult(TestMatrix topTestMatrix, TestMatrix bottomTestMatrix) { + Matrix top = GetMatrix(topTestMatrix); + Matrix bottom = GetMatrix(bottomTestMatrix); + // IF Assume.That(top.ColumnCount, Is.EqualTo(bottom.ColumnCount)); @@ -315,8 +333,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanDiagonalStack(Matrix left, Matrix right) + public void CanDiagonalStack(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix) { + Matrix left = GetMatrix(leftTestMatrix); + Matrix right = GetMatrix(rightTestMatrix); + var result = left.DiagonalStack(right); Assert.That(result.RowCount, Is.EqualTo(left.RowCount + right.RowCount)); @@ -341,8 +362,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanDiagonalStackIntoResult(Matrix left, Matrix right) + public void CanDiagonalStackIntoResult(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix) { + Matrix left = GetMatrix(leftTestMatrix); + Matrix right = GetMatrix(rightTestMatrix); + var result = Matrix.Build.Dense(left.RowCount + right.RowCount, left.ColumnCount + right.ColumnCount); left.DiagonalStack(right, result); diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs index 7c5e6282..20a8bf80 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -39,6 +39,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests public abstract partial class MatrixStructureTheory where T : struct, IEquatable, IFormattable { + protected abstract Matrix GetMatrix(TestMatrix matrix); + protected readonly T Zero = Matrix.Build.Zero; protected Matrix CreateDenseFor(Matrix m, int rows = -1, int columns = -1, int seed = 1) @@ -56,8 +58,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void IsEqualToItself(Matrix matrix) + public void IsEqualToItself(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); Assert.That(matrix, Is.EqualTo(matrix)); Assert.IsTrue(matrix.Equals(matrix)); Assert.IsTrue(matrix.Equals((object)matrix)); @@ -67,10 +70,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void IsNotEqualToOthers(Matrix left, Matrix right) + public void IsNotEqualToOthers(TestMatrix leftTestMatrix, TestMatrix rightTestmatrix) { + Matrix left = GetMatrix(leftTestMatrix); + Matrix right = GetMatrix(rightTestmatrix); + // IF (assuming we don't have duplicate data points) - Assume.That(left, Is.Not.SameAs(right)); + Assume.That(leftTestMatrix, Is.Not.EqualTo(rightTestmatrix)); // THEN Assert.That(left, Is.Not.EqualTo(right)); @@ -82,8 +88,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void IsNotEqualToPermutation(Matrix matrix) + public void IsNotEqualToPermutation(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); if (!matrix.Storage.IsFullyMutable) { return; @@ -114,8 +121,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void IsNotEqualToNonMatrixType(Matrix matrix) + public void IsNotEqualToNonMatrixType(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); Assert.That(matrix, Is.Not.EqualTo(2)); Assert.IsFalse(matrix.Equals(2)); Assert.IsFalse(matrix.Equals((object)2)); @@ -124,8 +132,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanClone(Matrix matrix) + public void CanClone(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var clone = matrix.Clone(); Assert.That(clone, Is.Not.SameAs(matrix)); Assert.That(clone, Is.EqualTo(matrix)); @@ -135,8 +144,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests #if !PORTABLE [Theory] - public void CanCloneUsingICloneable(Matrix matrix) + public void CanCloneUsingICloneable(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var clone = (Matrix)((ICloneable)matrix).Clone(); Assert.That(clone, Is.Not.SameAs(matrix)); Assert.That(clone, Is.EqualTo(matrix)); @@ -146,8 +156,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests #endif [Theory] - public void CanCopyTo(Matrix matrix) + public void CanCopyTo(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.CopyTo(dense); Assert.That(dense, Is.EqualTo(matrix)); @@ -165,22 +176,25 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanGetHashCode(Matrix matrix) + public void CanGetHashCode(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); Assert.That(matrix.GetHashCode(), Is.Not.EqualTo(Matrix.Build.SameAs(matrix).GetHashCode())); } [Theory] - public void CanClear(Matrix matrix) + public void CanClear(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var cleared = matrix.Clone(); cleared.Clear(); Assert.That(cleared, Is.EqualTo(Matrix.Build.SameAs(matrix))); } [Theory] - public void CanClearSubMatrix(Matrix matrix) + public void CanClearSubMatrix(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); Assume.That(matrix.RowCount, Is.GreaterThanOrEqualTo(2)); Assume.That(matrix.ColumnCount, Is.GreaterThanOrEqualTo(2)); @@ -193,8 +207,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanClearRows(Matrix matrix) + public void CanClearRows(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); Assume.That(matrix.RowCount, Is.GreaterThanOrEqualTo(2)); var cleared = matrix.Clone(); @@ -204,8 +219,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanClearColumns(Matrix matrix) + public void CanClearColumns(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); Assume.That(matrix.ColumnCount, Is.GreaterThanOrEqualTo(2)); var cleared = matrix.Clone(); @@ -215,8 +231,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanToArray(Matrix matrix) + public void CanToArray(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var array = matrix.ToArray(); Assert.That(array.GetLength(0), Is.EqualTo(matrix.RowCount)); Assert.That(array.GetLength(1), Is.EqualTo(matrix.ColumnCount)); @@ -230,8 +247,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanToColumnArrays(Matrix matrix) + public void CanToColumnArrays(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var columnArrays = matrix.ToColumnArrays(); Assert.That(columnArrays.Length, Is.EqualTo(matrix.ColumnCount)); Assert.That(columnArrays[0].Length, Is.EqualTo(matrix.RowCount)); @@ -245,8 +263,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanToRowArrays(Matrix matrix) + public void CanToRowArrays(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var rowArrays = matrix.ToRowArrays(); Assert.That(rowArrays.Length, Is.EqualTo(matrix.RowCount)); Assert.That(rowArrays[0].Length, Is.EqualTo(matrix.ColumnCount)); @@ -260,8 +279,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanToColumnWiseArray(Matrix matrix) + public void CanToColumnWiseArray(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var array = matrix.ToColumnWiseArray(); Assert.That(array.Length, Is.EqualTo(matrix.RowCount*matrix.ColumnCount)); for (int i = 0; i < array.Length; i++) @@ -271,8 +291,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanToRowWiseArray(Matrix matrix) + public void CanToRowWiseArray(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var array = matrix.ToRowWiseArray(); Assert.That(array.Length, Is.EqualTo(matrix.RowCount*matrix.ColumnCount)); for (int i = 0; i < array.Length; i++) @@ -282,8 +303,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void CanCreateSameKind(Matrix matrix) + public void CanCreateSameKind(TestMatrix testMatrix) { + Matrix matrix = GetMatrix(testMatrix); var empty = Matrix.Build.SameAs(matrix, 5, 6); Assert.That(empty, Is.EqualTo(Matrix.Build.Dense(5, 6))); Assert.That(empty.Storage.IsDense, Is.EqualTo(matrix.Storage.IsDense)); diff --git a/src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs index 2ced7ab6..6e3dad3f 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/DenseVectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single @@ -37,13 +36,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public class DenseVectorArithmeticTheory : VectorArithmeticTheory { [Datapoints] - Vector[] denseVectors = + TestVector[] _denseVectors = { - Vector.Build.Dense(new float[] { 1, 2, 3, 4, 5 }), - Vector.Build.Dense(new float[] { 2, 0, 0, -5, 0 }) + TestVector.Dense5, + TestVector.Dense5WithZeros }; [Datapoints] - float[] scalars = { 2f }; + float[] _scalars = { 2f }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs index 57de2252..6328cc61 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -36,25 +36,30 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single [TestFixture, Category("LA")] public class MatrixStructureTheory : MatrixStructureTheory { + protected override Matrix GetMatrix(TestMatrix matrix) + { + return TestData.GetMatrix(matrix); + } + [Datapoints] - Matrix[] _matrices = + TestMatrix[] _matrices = { - Matrix.Build.DenseOfArray(new[,] { { 1f, 1f, 2f }, { 1f, 1f, 2f }, { 1f, 1f, 2f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, 1.1f, 2.2f }, { -4.4f, 5.5f, 6.6f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { 0f, 1.1f, 2.2f, 3.3f }, { 1f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f }, { 0f, 1.1f }, { -4.4f, 5.5f } }), - Matrix.Build.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, 1.1f, 2.2f } }), - Matrix.Build.DenseOfArray(new[,] { { 1f, 2f, 3f }, { 2f, 2f, 0f }, { 3f, 0f, 3f } }), + TestMatrix.DenseSquare3x3, + TestMatrix.DenseSquare3x3b, + TestMatrix.DenseSquare4x4, + TestMatrix.DenseSquare4x4b, + TestMatrix.DenseTall3x2, + TestMatrix.DenseWide2x3, + TestMatrix.DenseSquare3x3c, - Matrix.Build.SparseOfArray(new[,] { { 7f, 1f, 2f }, { 1f, 1f, 2f }, { 1f, 1f, 2f } }), - Matrix.Build.SparseOfArray(new[,] { { 7f, 1f, 2f }, { 1f, 0f, 0f }, { -2f, 0f, 0f } }), - Matrix.Build.SparseOfArray(new[,] { { -1.1f, 0f, 0f }, { 0f, 1.1f, 2.2f } }), + TestMatrix.SparseSquare3x3, + TestMatrix.SparseSquare3x3b, + TestMatrix.SparseWide2x3, - Matrix.Build.Diagonal(3, 3, new[] { 1f, -2f, 1.5f }), - Matrix.Build.Diagonal(3, 3, new[] { 1f, 0f, -1.5f }), + TestMatrix.DiagonalSquare3x3, + TestMatrix.DiagonalSquare3x3b, - new UserDefinedMatrix(new[,] { { 0f, 1f, 2f }, { -1f, 7.7f, 0f }, { -2f, 0f, 0f } }) + TestMatrix.UserSquare3x3 }; [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Single/SparseVectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/SparseVectorArithmeticTheory.cs index e0e1c35b..9824278c 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/SparseVectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/SparseVectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2013 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,7 +28,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single @@ -37,15 +36,15 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public class SparseVectorArithmeticTheory : VectorArithmeticTheory { [Datapoints] - Vector[] denseVectors = + TestVector[] _sparseVectors = { - Vector.Build.SparseOfEnumerable(new float[] { 1, 2, 3, 4, 5 }), - Vector.Build.SparseOfEnumerable(new float[] { 2, 0, 0, -5, 0 }), - Vector.Build.Sparse(5), - Vector.Build.Sparse(int.MaxValue) + TestVector.Sparse5, + TestVector.Sparse5WithZeros, + TestVector.Sparse5AllZeros, + TestVector.SparseMaxLengthAllZeros }; [Datapoints] - float[] scalars = { 2f }; + float[] _scalars = { 2f }; } } diff --git a/src/UnitTests/LinearAlgebraTests/Single/TestData.cs b/src/UnitTests/LinearAlgebraTests/Single/TestData.cs new file mode 100644 index 00000000..112fd3a2 --- /dev/null +++ b/src/UnitTests/LinearAlgebraTests/Single/TestData.cs @@ -0,0 +1,82 @@ +// +// Math.NET Numerics, part of the Math.NET Project +// http://numerics.mathdotnet.com +// http://github.com/mathnet/mathnet-numerics +// http://mathnetnumerics.codeplex.com +// +// Copyright (c) 2009-2015 Math.NET +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using MathNet.Numerics.LinearAlgebra; + +namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single +{ + public static class TestData + { + static readonly MatrixBuilder M = Matrix.Build; + static readonly VectorBuilder V = Vector.Build; + + public static Matrix GetMatrix(TestMatrix matrix) + { + switch (matrix) + { + case TestMatrix.DenseSquare3x3: return M.DenseOfArray(new[,] { { 1f, 1f, 2f }, { 1f, 1f, 2f }, { 1f, 1f, 2f } }); + case TestMatrix.DenseSquare3x3b: return M.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, 1.1f, 2.2f }, { -4.4f, 5.5f, 6.6f } }); + case TestMatrix.DenseSquare3x3c: return M.DenseOfArray(new[,] { { 1f, 2f, 3f }, { 2f, 2f, 0f }, { 3f, 0f, 3f } }); + case TestMatrix.DenseSquare4x4: return M.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { 0f, 1.1f, 2.2f, 3.3f }, { 1f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }); + case TestMatrix.DenseSquare4x4b: return M.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }); + case TestMatrix.DenseTall3x2: return M.DenseOfArray(new[,] { { -1.1f, -2.2f }, { 0f, 1.1f }, { -4.4f, 5.5f } }); + case TestMatrix.DenseWide2x3: return M.DenseOfArray(new[,] { { -1.1f, -2.2f, -3.3f }, { 0f, 1.1f, 2.2f } }); + + case TestMatrix.SparseSquare3x3: return M.SparseOfArray(new[,] { { 7f, 1f, 2f }, { 1f, 1f, 2f }, { 1f, 1f, 2f } }); + case TestMatrix.SparseSquare3x3b: return M.SparseOfArray(new[,] { { 7f, 1f, 2f }, { 1f, 0f, 0f }, { -2f, 0f, 0f } }); + case TestMatrix.SparseWide2x3: return M.SparseOfArray(new[,] { { -1.1f, 0f, 0f }, { 0f, 1.1f, 2.2f } }); + + case TestMatrix.DiagonalSquare3x3: return M.Diagonal(3, 3, new[] { 1f, -2f, 1.5f }); + case TestMatrix.DiagonalSquare3x3b: return M.Diagonal(3, 3, new[] { 1f, 0f, -1.5f }); + + case TestMatrix.UserSquare3x3: return new UserDefinedMatrix(new[,] { { 0f, 1f, 2f }, { -1f, 7.7f, 0f }, { -2f, 0f, 0f } }); + + default: throw new NotSupportedException(); + } + } + + public static Vector GetVector(TestVector vector) + { + switch (vector) + { + case TestVector.Dense5: return V.Dense(new float[] { 1, 2, 3, 4, 5 }); + case TestVector.Dense5WithZeros: return V.Dense(new float[] { 2, 0, 0, -5, 0 }); + + case TestVector.Sparse5: return V.SparseOfEnumerable(new float[] { 1, 2, 3, 4, 5 }); + case TestVector.Sparse5WithZeros: return V.SparseOfEnumerable(new float[] { 2, 0, 0, -5, 0 }); + case TestVector.Sparse5AllZeros: return V.Sparse(5); + case TestVector.SparseMaxLengthAllZeros: return V.Sparse(int.MaxValue); + + default: throw new NotSupportedException(); + } + } + } +} diff --git a/src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs index 9fb6d25f..3dd8c7cb 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -28,13 +28,19 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.LinearAlgebra; +using NUnit.Framework; + namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single { - using NUnit.Framework; - [TestFixture, Category("LA")] public abstract class VectorArithmeticTheory : VectorArithmeticTheory { + protected override Vector GetVector(TestVector vector) + { + return TestData.GetVector(vector); + } + protected override float Minus(float value) { return -value; } protected override float Add(float first, float second) { return first + second; } } diff --git a/src/UnitTests/LinearAlgebraTests/TestData.cs b/src/UnitTests/LinearAlgebraTests/TestData.cs new file mode 100644 index 00000000..d9c23a46 --- /dev/null +++ b/src/UnitTests/LinearAlgebraTests/TestData.cs @@ -0,0 +1,63 @@ +// +// Math.NET Numerics, part of the Math.NET Project +// http://numerics.mathdotnet.com +// http://github.com/mathnet/mathnet-numerics +// http://mathnetnumerics.codeplex.com +// +// Copyright (c) 2009-2015 Math.NET +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +namespace MathNet.Numerics.UnitTests.LinearAlgebraTests +{ + public enum TestMatrix + { + DenseSquare3x3, + DenseSquare3x3b, + DenseSquare4x4, + DenseSquare4x4b, + DenseTall3x2, + DenseWide2x3, + DenseSquare3x3c, + + SparseSquare3x3, + SparseSquare3x3b, + SparseWide2x3, + + DiagonalSquare3x3, + DiagonalSquare3x3b, + + UserSquare3x3 + } + + public enum TestVector + { + Dense5, + Dense5WithZeros, + + Sparse5, + Sparse5WithZeros, + Sparse5AllZeros, + SparseMaxLengthAllZeros + } +} \ No newline at end of file diff --git a/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs index 23e97597..bdd9f752 100644 --- a/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs @@ -4,7 +4,7 @@ // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // -// Copyright (c) 2009-2011 Math.NET +// Copyright (c) 2009-2015 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -39,13 +39,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests public abstract class VectorArithmeticTheory where T : struct, IEquatable, IFormattable { + protected abstract Vector GetVector(TestVector vector); + protected abstract T Minus(T value); protected abstract T Add(T first, T second); private T Subtract(T first, T second) { return Add(first, Minus(second)); } [Theory, Timeout(200)] - public void CanEqualVector(Vector vector, T scalar) + public void CanEqualVector(TestVector testVector, T scalar) { + Vector vector = GetVector(testVector); + Assert.That(vector.Equals(vector)); var a = vector.Clone(); @@ -77,8 +81,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory, Timeout(200)] - public void CanNegateVector(Vector vector) + public void CanNegateVector(TestVector testVector) { + Vector vector = GetVector(testVector); + var hash = vector.GetHashCode(); var result1 = -vector; @@ -99,8 +105,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory, Timeout(200)] - public void CanAddTwoVectors(Vector a, Vector b) + public void CanAddTwoVectors(TestVector testVectorA, TestVector testVectorB) { + Vector a = GetVector(testVectorA); + Vector b = GetVector(testVectorB); Assume.That(a.Count, Is.EqualTo(b.Count)); var hasha = a.GetHashCode(); @@ -131,8 +139,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory, Timeout(200)] - public void CanAddScalarToVector(Vector vector, T scalar) + public void CanAddScalarToVector(TestVector testVector, T scalar) { + Vector vector = GetVector(testVector); Assume.That(vector.Count, Is.LessThan(100)); var hash = vector.GetHashCode(); @@ -154,8 +163,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory, Timeout(200)] - public void CanSubtractTwoVectors(Vector a, Vector b) + public void CanSubtractTwoVectors(TestVector testVectorA, TestVector testVectorB) { + Vector a = GetVector(testVectorA); + Vector b = GetVector(testVectorB); Assume.That(a.Count, Is.EqualTo(b.Count)); var hasha = a.GetHashCode(); @@ -186,8 +197,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory, Timeout(200)] - public void CanSubtractScalarFromVector(Vector vector, T scalar) + public void CanSubtractScalarFromVector(TestVector testVector, T scalar) { + Vector vector = GetVector(testVector); Assume.That(vector.Count, Is.LessThan(100)); var hash = vector.GetHashCode(); diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index 54482cd3..35bc5c1f 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -188,6 +188,7 @@ + @@ -235,6 +236,7 @@ + @@ -282,6 +284,7 @@ + @@ -333,6 +336,7 @@ + @@ -342,6 +346,7 @@ +