From 36b568c5f12371a587829c01cb9b1446728d13cf Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 22 Mar 2015 12:08:26 +0100 Subject: [PATCH] Tests: cleanup, simplifications --- MathNet.Numerics.sln.DotSettings | 1 + src/UnitTests/LinearAlgebraTests/Build.cs | 73 ------------------- .../Complex/MatrixStructureTheory.cs | 4 +- .../LinearAlgebraTests/Complex/TestData.cs | 4 +- .../Complex/VectorArithmeticTheory.cs | 7 +- .../Complex32/MatrixStructureTheory.cs | 4 +- .../LinearAlgebraTests/Complex32/TestData.cs | 4 +- .../Complex32/VectorArithmeticTheory.cs | 7 +- .../Double/MatrixStructureTheory.cs | 4 +- .../LinearAlgebraTests/Double/TestData.cs | 4 +- .../Double/VectorArithmeticTheory.cs | 7 +- .../MatrixStructureTheory.Access.cs | 52 ++++++------- .../MatrixStructureTheory.Functional.cs | 20 ++--- .../MatrixStructureTheory.Reform.cs | 64 ++++++---------- .../MatrixStructureTheory.cs | 42 +++++------ .../Single/MatrixStructureTheory.cs | 4 +- .../LinearAlgebraTests/Single/TestData.cs | 4 +- .../Single/VectorArithmeticTheory.cs | 7 +- src/UnitTests/LinearAlgebraTests/TestData.cs | 48 ++++++++++++ .../VectorArithmeticTheory.cs | 61 +++++++--------- .../VectorStorageCombinatorsTests.cs | 72 +++++++++--------- src/UnitTests/UnitTests.csproj | 1 - 22 files changed, 217 insertions(+), 277 deletions(-) delete mode 100644 src/UnitTests/LinearAlgebraTests/Build.cs diff --git a/MathNet.Numerics.sln.DotSettings b/MathNet.Numerics.sln.DotSettings index 6cec424b..d4811bc7 100644 --- a/MathNet.Numerics.sln.DotSettings +++ b/MathNet.Numerics.sln.DotSettings @@ -102,6 +102,7 @@ OTHER DEALINGS IN THE SOFTWARE. SVD TFQMR WH + True True True <data /> diff --git a/src/UnitTests/LinearAlgebraTests/Build.cs b/src/UnitTests/LinearAlgebraTests/Build.cs deleted file mode 100644 index ce254596..00000000 --- a/src/UnitTests/LinearAlgebraTests/Build.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -// 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-2014 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 System.Collections.Generic; -using MathNet.Numerics.LinearAlgebra.Storage; - -namespace MathNet.Numerics.UnitTests.LinearAlgebraTests -{ - public enum VectorStorageType - { - DenseVector = 1, - SparseVector = 2 - } - - public static class Build - { - public static VectorStorage VectorStorage(VectorStorageType type, IEnumerable data) - where T : struct, IEquatable, IFormattable - { - switch (type) - { - case VectorStorageType.DenseVector: - return DenseVectorStorage.OfEnumerable(data); - case VectorStorageType.SparseVector: - return SparseVectorStorage.OfEnumerable(data); - default: - throw new NotSupportedException(); - } - } - - public static VectorStorage VectorStorage(VectorStorageType type, int length) - where T : struct, IEquatable, IFormattable - { - switch (type) - { - case VectorStorageType.DenseVector: - return new DenseVectorStorage(length); - case VectorStorageType.SparseVector: - return new SparseVectorStorage(length); - default: - throw new NotSupportedException(); - } - } - } -} diff --git a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs index 1019d529..8b3c6622 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/MatrixStructureTheory.cs @@ -42,9 +42,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex [TestFixture, Category("LA")] public class MatrixStructureTheory : MatrixStructureTheory { - protected override Matrix GetMatrix(TestMatrix matrix) + protected override Matrix Get(TestMatrix matrix) { - return TestData.GetMatrix(matrix); + return TestData.Matrix(matrix); } [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Complex/TestData.cs b/src/UnitTests/LinearAlgebraTests/Complex/TestData.cs index fe2e826a..b93a7e89 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/TestData.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/TestData.cs @@ -44,7 +44,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex static readonly MatrixBuilder M = Matrix.Build; static readonly VectorBuilder V = Vector.Build; - public static Matrix GetMatrix(TestMatrix matrix) + public static Matrix Matrix(TestMatrix matrix) { switch (matrix) { @@ -68,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex } } - public static Vector GetVector(TestVector vector) + public static Vector Vector(TestVector vector) { switch (vector) { diff --git a/src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs index 5f39a0fa..ebbef2ef 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/VectorArithmeticTheory.cs @@ -42,14 +42,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex [TestFixture, Category("LA")] public class VectorArithmeticTheory : VectorArithmeticTheory { - protected override Vector GetVector(TestVector vector) + protected override Vector Get(TestVector vector) { - return TestData.GetVector(vector); + return TestData.Vector(vector); } - protected override Complex Minus(Complex value) { return -value; } - protected override Complex Add(Complex first, Complex second) { return first + second; } - [Datapoints] TestVector[] _vectors = { diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs index 9778f5d8..c1353487 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/MatrixStructureTheory.cs @@ -38,9 +38,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 [TestFixture, Category("LA")] public class MatrixStructureTheory : MatrixStructureTheory { - protected override Matrix GetMatrix(TestMatrix matrix) + protected override Matrix Get(TestMatrix matrix) { - return TestData.GetMatrix(matrix); + return TestData.Matrix(matrix); } [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs b/src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs index ef4ca885..c778d042 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/TestData.cs @@ -40,7 +40,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 static readonly MatrixBuilder M = Matrix.Build; static readonly VectorBuilder V = Vector.Build; - public static Matrix GetMatrix(TestMatrix matrix) + public static Matrix Matrix(TestMatrix matrix) { switch (matrix) { @@ -65,7 +65,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 } } - public static Vector GetVector(TestVector vector) + public static Vector Vector(TestVector vector) { switch (vector) { diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs index d5a4010d..3dee3244 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorArithmeticTheory.cs @@ -38,14 +38,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 [TestFixture, Category("LA")] public class VectorArithmeticTheory : VectorArithmeticTheory { - protected override Vector GetVector(TestVector vector) + protected override Vector Get(TestVector vector) { - return TestData.GetVector(vector); + return TestData.Vector(vector); } - protected override Complex32 Minus(Complex32 value) { return -value; } - protected override Complex32 Add(Complex32 first, Complex32 second) { return first + second; } - [Datapoints] TestVector[] _vectors = { diff --git a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs index 3dde825a..83e59d4e 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/MatrixStructureTheory.cs @@ -36,9 +36,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double [TestFixture, Category("LA")] public class MatrixStructureTheory : MatrixStructureTheory { - protected override Matrix GetMatrix(TestMatrix matrix) + protected override Matrix Get(TestMatrix matrix) { - return TestData.GetMatrix(matrix); + return TestData.Matrix(matrix); } [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Double/TestData.cs b/src/UnitTests/LinearAlgebraTests/Double/TestData.cs index 4a406451..012d22c0 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/TestData.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/TestData.cs @@ -38,7 +38,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double static readonly MatrixBuilder M = Matrix.Build; static readonly VectorBuilder V = Vector.Build; - public static Matrix GetMatrix(TestMatrix matrix) + public static Matrix Matrix(TestMatrix matrix) { switch (matrix) { @@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double } } - public static Vector GetVector(TestVector vector) + public static Vector Vector(TestVector vector) { switch (vector) { diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs index 756b4780..e4ca083f 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/VectorArithmeticTheory.cs @@ -36,14 +36,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double [TestFixture, Category("LA")] public class VectorArithmeticTheory : VectorArithmeticTheory { - protected override Vector GetVector(TestVector vector) + protected override Vector Get(TestVector vector) { - return TestData.GetVector(vector); + return TestData.Vector(vector); } - protected override double Minus(double value) { return -value; } - protected override double Add(double first, double second) { return first + second; } - [Datapoints] TestVector[] _vectors = { diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs index 63af3fe5..af96d042 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Access.cs @@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetFieldsByIndex(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); Assert.That(() => matrix[0, 0], Throws.Nothing); Assert.That(() => matrix[0, matrix.ColumnCount - 1], Throws.Nothing); @@ -53,7 +53,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetRow(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // First Row var firstrow = matrix.Row(0); @@ -79,7 +79,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetRowIntoResult(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var row = Vector.Build.Dense(matrix.ColumnCount); matrix.Row(0, row); @@ -97,7 +97,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetRowWithRange(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // First Row, Columns 0..1 var firstrow = matrix.Row(0, 0, 2); @@ -134,7 +134,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetRowWithRangeIntoResult(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var row = Vector.Build.Dense(matrix.ColumnCount - 1); matrix.Row(0, 1, matrix.ColumnCount - 1, row); @@ -153,7 +153,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetColumn(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // First Column var firstcol = matrix.Column(0); @@ -179,7 +179,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetColumnIntoResult(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var col = Vector.Build.Dense(matrix.RowCount); matrix.Column(0, col); @@ -197,7 +197,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetColumnWithRange(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // First Column, Rows 0..1 var firstcol = matrix.Column(0, 0, 2); @@ -234,7 +234,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetColumnWithRangeIntoResult(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var col = Vector.Build.Dense(matrix.RowCount - 1); matrix.Column(0, 1, matrix.RowCount - 1, col); @@ -253,7 +253,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanSetRow(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // First Row var m = matrix.Clone(); @@ -290,7 +290,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanSetRowArray(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // First Row var m = matrix.Clone(); @@ -325,7 +325,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanSetColumn(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // First Column var m = matrix.Clone(); @@ -362,7 +362,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanSetColumnArray(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // First Column var m = matrix.Clone(); @@ -397,7 +397,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetUpperTriangle(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var upper = matrix.UpperTriangle(); for (var i = 0; i < matrix.RowCount; i++) @@ -412,7 +412,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetUpperTriangleIntoResult(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.UpperTriangle(dense); @@ -442,7 +442,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetLowerTriangle(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var upper = matrix.LowerTriangle(); for (var i = 0; i < matrix.RowCount; i++) @@ -457,7 +457,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetLowerTriangleIntoResult(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.LowerTriangle(dense); @@ -487,7 +487,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetStrictlyUpperTriangle(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var upper = matrix.StrictlyUpperTriangle(); for (var i = 0; i < matrix.RowCount; i++) @@ -502,7 +502,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetStrictlyUpperTriangleIntoResult(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.StrictlyUpperTriangle(dense); @@ -532,7 +532,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetStrictlyLowerTriangle(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var upper = matrix.StrictlyLowerTriangle(); for (var i = 0; i < matrix.RowCount; i++) @@ -547,7 +547,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetStrictlyLowerTriangleIntoResult(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.StrictlyLowerTriangle(dense); @@ -577,7 +577,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetDiagonal(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var diag = matrix.Diagonal(); Assert.That(diag.Count, Is.EqualTo(Math.Min(matrix.RowCount, matrix.ColumnCount))); @@ -590,7 +590,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanSetDiagonal(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var m = matrix.Clone(); var v = CreateVectorFor(m, Math.Min(matrix.RowCount, matrix.ColumnCount)); @@ -612,7 +612,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanSetDiagonalArray(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var m = matrix.Clone(); m.SetDiagonal(new T[Math.Min(matrix.RowCount, matrix.ColumnCount)]); @@ -633,7 +633,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetSubmatrix(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // Top Left Corner 2x2 var topleft = matrix.SubMatrix(0, 2, 0, 2); @@ -677,7 +677,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanSetSubmatrix(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // Top Left Corner 2x2 var topleft = CreateDenseFor(matrix, 2, 2); diff --git a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs index bd1b133e..72211716 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs @@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanMap(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(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)); @@ -68,7 +68,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanMapIndexed(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); Matrix a = matrix.MapIndexed((i, j, x) => { if (i != 0 || j != 1) Assert.That(matrix.At(i, j), Is.EqualTo(x)); @@ -105,7 +105,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanMapInplace(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var a = matrix.Clone(); a.MapInplace(x => x, Zeros.AllowSkip); Assert.That(a, Is.EqualTo(matrix)); @@ -124,7 +124,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanMapIndexedInplace(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var a = matrix.Clone(); a.MapIndexedInplace((i, j, x) => { @@ -152,7 +152,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanMapSubMatrixToSame(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); T one = Matrix.Build.One; // Full Range - not forced @@ -176,7 +176,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanMapSubMatrixToDense(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); T one = Matrix.Build.One; // Full Range - not forced @@ -217,7 +217,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanMapSubMatrixToSparse(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); T one = Matrix.Build.One; // Full Range - filled, not forced @@ -267,7 +267,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanFoldRows(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // not forced T[] rowSum = matrix.FoldByRow((s, x) => Operator.Add(s, x), Operator.Zero, Zeros.AllowSkip); @@ -290,7 +290,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanFoldColumns(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); // not forced T[] colSum = matrix.FoldByColumn((s, x) => Operator.Add(s, x), Operator.Zero, Zeros.AllowSkip); @@ -313,7 +313,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanFold2(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(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 d68d6801..52f5e1e6 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Reform.cs @@ -40,19 +40,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanPermuteRows(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); + Assume.That(matrix.Storage.IsFullyMutable); + var m = matrix.Clone(); var rnd = new System.Random(0); var permutation = new Permutation(Enumerable.Range(0, matrix.RowCount).OrderBy(i => rnd.Next()).ToArray()); - try - { - m.PermuteRows(permutation); - } - catch (InvalidOperationException) - { - Assert.Ignore("Matrix type {0} does not support permutations", matrix.GetType().FullName); - } + m.PermuteRows(permutation); Assert.That(m, Is.Not.SameAs(matrix)); Assert.That(m.RowCount, Is.EqualTo(matrix.RowCount)); @@ -70,19 +65,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanPermuteColumns(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); + Assume.That(matrix.Storage.IsFullyMutable); + var m = matrix.Clone(); var rnd = new System.Random(0); var permutation = new Permutation(Enumerable.Range(0, matrix.ColumnCount).OrderBy(i => rnd.Next()).ToArray()); - try - { - m.PermuteColumns(permutation); - } - catch (InvalidOperationException) - { - Assert.Ignore("Matrix type {0} does not support permutations", matrix.GetType().FullName); - } + m.PermuteColumns(permutation); Assert.That(m, Is.Not.SameAs(matrix)); Assert.That(m.RowCount, Is.EqualTo(matrix.RowCount)); @@ -100,7 +90,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanInsertRow(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var row = Vector.Build.Random(matrix.ColumnCount, 0); for (var position = 0; position < matrix.RowCount + 1; position++) { @@ -137,7 +127,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanRemoveRow(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); for (var position = 0; position < matrix.RowCount; position++) { var result = matrix.RemoveRow(position); @@ -162,7 +152,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanInsertColumn(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var column = Vector.Build.Random(matrix.RowCount, 0); for (var position = 0; position < matrix.ColumnCount + 1; position++) { @@ -199,7 +189,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanRemoveColumn(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); for (var position = 0; position < matrix.ColumnCount; position++) { var result = matrix.RemoveColumn(position); @@ -225,10 +215,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanAppend(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix) { - Matrix left = GetMatrix(leftTestMatrix); - Matrix right = GetMatrix(rightTestMatrix); - - // IF + Matrix left = Get(leftTestMatrix); + Matrix right = Get(rightTestMatrix); Assume.That(left.RowCount, Is.EqualTo(right.RowCount)); // THEN @@ -250,10 +238,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanAppendIntoResult(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix) { - Matrix left = GetMatrix(leftTestMatrix); - Matrix right = GetMatrix(rightTestMatrix); - - // IF + Matrix left = Get(leftTestMatrix); + Matrix right = Get(rightTestMatrix); Assume.That(left.RowCount, Is.EqualTo(right.RowCount)); // THEN @@ -280,8 +266,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanStack(TestMatrix topTestMatrix, TestMatrix bottomTestMatrix) { - Matrix top = GetMatrix(topTestMatrix); - Matrix bottom = GetMatrix(bottomTestMatrix); + Matrix top = Get(topTestMatrix); + Matrix bottom = Get(bottomTestMatrix); // IF Assume.That(top.ColumnCount, Is.EqualTo(bottom.ColumnCount)); @@ -305,10 +291,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanStackIntoResult(TestMatrix topTestMatrix, TestMatrix bottomTestMatrix) { - Matrix top = GetMatrix(topTestMatrix); - Matrix bottom = GetMatrix(bottomTestMatrix); - - // IF + Matrix top = Get(topTestMatrix); + Matrix bottom = Get(bottomTestMatrix); Assume.That(top.ColumnCount, Is.EqualTo(bottom.ColumnCount)); // THEN @@ -335,8 +319,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanDiagonalStack(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix) { - Matrix left = GetMatrix(leftTestMatrix); - Matrix right = GetMatrix(rightTestMatrix); + Matrix left = Get(leftTestMatrix); + Matrix right = Get(rightTestMatrix); var result = left.DiagonalStack(right); @@ -364,8 +348,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanDiagonalStackIntoResult(TestMatrix leftTestMatrix, TestMatrix rightTestMatrix) { - Matrix left = GetMatrix(leftTestMatrix); - Matrix right = GetMatrix(rightTestMatrix); + Matrix left = Get(leftTestMatrix); + Matrix right = Get(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 20a8bf80..44e5348a 100644 --- a/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.cs @@ -39,7 +39,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests public abstract partial class MatrixStructureTheory where T : struct, IEquatable, IFormattable { - protected abstract Matrix GetMatrix(TestMatrix matrix); + protected abstract Matrix Get(TestMatrix matrix); protected readonly T Zero = Matrix.Build.Zero; @@ -60,7 +60,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void IsEqualToItself(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); Assert.That(matrix, Is.EqualTo(matrix)); Assert.IsTrue(matrix.Equals(matrix)); Assert.IsTrue(matrix.Equals((object)matrix)); @@ -72,10 +72,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void IsNotEqualToOthers(TestMatrix leftTestMatrix, TestMatrix rightTestmatrix) { - Matrix left = GetMatrix(leftTestMatrix); - Matrix right = GetMatrix(rightTestmatrix); - - // IF (assuming we don't have duplicate data points) + Matrix left = Get(leftTestMatrix); + Matrix right = Get(rightTestmatrix); Assume.That(leftTestMatrix, Is.Not.EqualTo(rightTestmatrix)); // THEN @@ -90,7 +88,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void IsNotEqualToPermutation(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); if (!matrix.Storage.IsFullyMutable) { return; @@ -123,7 +121,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void IsNotEqualToNonMatrixType(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); Assert.That(matrix, Is.Not.EqualTo(2)); Assert.IsFalse(matrix.Equals(2)); Assert.IsFalse(matrix.Equals((object)2)); @@ -134,7 +132,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanClone(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var clone = matrix.Clone(); Assert.That(clone, Is.Not.SameAs(matrix)); Assert.That(clone, Is.EqualTo(matrix)); @@ -146,7 +144,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanCloneUsingICloneable(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var clone = (Matrix)((ICloneable)matrix).Clone(); Assert.That(clone, Is.Not.SameAs(matrix)); Assert.That(clone, Is.EqualTo(matrix)); @@ -158,7 +156,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanCopyTo(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var dense = Matrix.Build.Dense(matrix.RowCount, matrix.ColumnCount); matrix.CopyTo(dense); Assert.That(dense, Is.EqualTo(matrix)); @@ -178,14 +176,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanGetHashCode(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); Assert.That(matrix.GetHashCode(), Is.Not.EqualTo(Matrix.Build.SameAs(matrix).GetHashCode())); } [Theory] public void CanClear(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var cleared = matrix.Clone(); cleared.Clear(); Assert.That(cleared, Is.EqualTo(Matrix.Build.SameAs(matrix))); @@ -194,7 +192,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanClearSubMatrix(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); Assume.That(matrix.RowCount, Is.GreaterThanOrEqualTo(2)); Assume.That(matrix.ColumnCount, Is.GreaterThanOrEqualTo(2)); @@ -209,7 +207,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanClearRows(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); Assume.That(matrix.RowCount, Is.GreaterThanOrEqualTo(2)); var cleared = matrix.Clone(); @@ -221,7 +219,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanClearColumns(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); Assume.That(matrix.ColumnCount, Is.GreaterThanOrEqualTo(2)); var cleared = matrix.Clone(); @@ -233,7 +231,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanToArray(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var array = matrix.ToArray(); Assert.That(array.GetLength(0), Is.EqualTo(matrix.RowCount)); Assert.That(array.GetLength(1), Is.EqualTo(matrix.ColumnCount)); @@ -249,7 +247,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanToColumnArrays(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var columnArrays = matrix.ToColumnArrays(); Assert.That(columnArrays.Length, Is.EqualTo(matrix.ColumnCount)); Assert.That(columnArrays[0].Length, Is.EqualTo(matrix.RowCount)); @@ -265,7 +263,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanToRowArrays(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var rowArrays = matrix.ToRowArrays(); Assert.That(rowArrays.Length, Is.EqualTo(matrix.RowCount)); Assert.That(rowArrays[0].Length, Is.EqualTo(matrix.ColumnCount)); @@ -281,7 +279,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanToColumnWiseArray(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var array = matrix.ToColumnWiseArray(); Assert.That(array.Length, Is.EqualTo(matrix.RowCount*matrix.ColumnCount)); for (int i = 0; i < array.Length; i++) @@ -293,7 +291,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanToRowWiseArray(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(testMatrix); var array = matrix.ToRowWiseArray(); Assert.That(array.Length, Is.EqualTo(matrix.RowCount*matrix.ColumnCount)); for (int i = 0; i < array.Length; i++) @@ -305,7 +303,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests [Theory] public void CanCreateSameKind(TestMatrix testMatrix) { - Matrix matrix = GetMatrix(testMatrix); + Matrix matrix = Get(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/MatrixStructureTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs index 6328cc61..26c515a2 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/MatrixStructureTheory.cs @@ -36,9 +36,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single [TestFixture, Category("LA")] public class MatrixStructureTheory : MatrixStructureTheory { - protected override Matrix GetMatrix(TestMatrix matrix) + protected override Matrix Get(TestMatrix matrix) { - return TestData.GetMatrix(matrix); + return TestData.Matrix(matrix); } [Datapoints] diff --git a/src/UnitTests/LinearAlgebraTests/Single/TestData.cs b/src/UnitTests/LinearAlgebraTests/Single/TestData.cs index 112fd3a2..bec07a26 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/TestData.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/TestData.cs @@ -38,7 +38,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single static readonly MatrixBuilder M = Matrix.Build; static readonly VectorBuilder V = Vector.Build; - public static Matrix GetMatrix(TestMatrix matrix) + public static Matrix Matrix(TestMatrix matrix) { switch (matrix) { @@ -63,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single } } - public static Vector GetVector(TestVector vector) + public static Vector Vector(TestVector vector) { switch (vector) { diff --git a/src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs index c550a92f..d7b4096d 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/VectorArithmeticTheory.cs @@ -36,14 +36,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single [TestFixture, Category("LA")] public class VectorArithmeticTheory : VectorArithmeticTheory { - protected override Vector GetVector(TestVector vector) + protected override Vector Get(TestVector vector) { - return TestData.GetVector(vector); + return TestData.Vector(vector); } - protected override float Minus(float value) { return -value; } - protected override float Add(float first, float second) { return first + second; } - [Datapoints] TestVector[] _vectors = { diff --git a/src/UnitTests/LinearAlgebraTests/TestData.cs b/src/UnitTests/LinearAlgebraTests/TestData.cs index d9c23a46..a9f65b8c 100644 --- a/src/UnitTests/LinearAlgebraTests/TestData.cs +++ b/src/UnitTests/LinearAlgebraTests/TestData.cs @@ -28,6 +28,10 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections.Generic; +using MathNet.Numerics.LinearAlgebra.Storage; + namespace MathNet.Numerics.UnitTests.LinearAlgebraTests { public enum TestMatrix @@ -50,6 +54,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests UserSquare3x3 } + public enum TestMatrixStorage + { + DenseMatrix = 1, + SparseMatrix = 2, + DiagonalMatrix = 3 + } + public enum TestVector { Dense5, @@ -60,4 +71,41 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests Sparse5AllZeros, SparseMaxLengthAllZeros } + + public enum TestVectorStorage + { + DenseVector = 1, + SparseVector = 2 + } + + public static class TestData + { + public static VectorStorage VectorStorage(TestVectorStorage type, IEnumerable data) + where T : struct, IEquatable, IFormattable + { + switch (type) + { + case TestVectorStorage.DenseVector: + return DenseVectorStorage.OfEnumerable(data); + case TestVectorStorage.SparseVector: + return SparseVectorStorage.OfEnumerable(data); + default: + throw new NotSupportedException(); + } + } + + public static VectorStorage VectorStorage(TestVectorStorage type, int length) + where T : struct, IEquatable, IFormattable + { + switch (type) + { + case TestVectorStorage.DenseVector: + return new DenseVectorStorage(length); + case TestVectorStorage.SparseVector: + return new SparseVectorStorage(length); + default: + throw new NotSupportedException(); + } + } + } } \ No newline at end of file diff --git a/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs b/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs index bdd9f752..9ebe3806 100644 --- a/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs +++ b/src/UnitTests/LinearAlgebraTests/VectorArithmeticTheory.cs @@ -28,10 +28,9 @@ // OTHER DEALINGS IN THE SOFTWARE. // -using System.Globalization; +using System; using MathNet.Numerics.LinearAlgebra; using NUnit.Framework; -using System; namespace MathNet.Numerics.UnitTests.LinearAlgebraTests { @@ -39,16 +38,12 @@ 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)); } + protected abstract Vector Get(TestVector vector); - [Theory, Timeout(200)] + [Theory] public void CanEqualVector(TestVector testVector, T scalar) { - Vector vector = GetVector(testVector); + Vector vector = Get(testVector); Assert.That(vector.Equals(vector)); @@ -80,10 +75,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests Assert.That(c.Equals(Vector.Build.SameAs(vector))); } - [Theory, Timeout(200)] + [Theory] public void CanNegateVector(TestVector testVector) { - Vector vector = GetVector(testVector); + Vector vector = Get(testVector); var hash = vector.GetHashCode(); @@ -99,16 +94,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(vector.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Minus(vector[i])), i.ToString(CultureInfo.InvariantCulture)); - Assert.That(result2[i], Is.EqualTo(Minus(vector[i])), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result1[i], Is.EqualTo(Operator.Negate(vector[i]))); + Assert.That(result2[i], Is.EqualTo(Operator.Negate(vector[i]))); } } - [Theory, Timeout(200)] + [Theory] public void CanAddTwoVectors(TestVector testVectorA, TestVector testVectorB) { - Vector a = GetVector(testVectorA); - Vector b = GetVector(testVectorB); + Vector a = Get(testVectorA); + Vector b = Get(testVectorB); Assume.That(a.Count, Is.EqualTo(b.Count)); var hasha = a.GetHashCode(); @@ -132,16 +127,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(a.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); - Assert.That(result2[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); - Assert.That(result3[i], Is.EqualTo(Add(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result1[i], Is.EqualTo(Operator.Add(a[i], b[i]))); + Assert.That(result2[i], Is.EqualTo(Operator.Add(a[i], b[i]))); + Assert.That(result3[i], Is.EqualTo(Operator.Add(a[i], b[i]))); } } - [Theory, Timeout(200)] + [Theory] public void CanAddScalarToVector(TestVector testVector, T scalar) { - Vector vector = GetVector(testVector); + Vector vector = Get(testVector); Assume.That(vector.Count, Is.LessThan(100)); var hash = vector.GetHashCode(); @@ -157,16 +152,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(vector.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Add(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture)); - Assert.That(result2[i], Is.EqualTo(Add(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result1[i], Is.EqualTo(Operator.Add(vector[i], scalar))); + Assert.That(result2[i], Is.EqualTo(Operator.Add(vector[i], scalar))); } } - [Theory, Timeout(200)] + [Theory] public void CanSubtractTwoVectors(TestVector testVectorA, TestVector testVectorB) { - Vector a = GetVector(testVectorA); - Vector b = GetVector(testVectorB); + Vector a = Get(testVectorA); + Vector b = Get(testVectorB); Assume.That(a.Count, Is.EqualTo(b.Count)); var hasha = a.GetHashCode(); @@ -190,16 +185,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(a.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); - Assert.That(result2[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); - Assert.That(result3[i], Is.EqualTo(Subtract(a[i], b[i])), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result1[i], Is.EqualTo(Operator.Subtract(a[i], b[i]))); + Assert.That(result2[i], Is.EqualTo(Operator.Subtract(a[i], b[i]))); + Assert.That(result3[i], Is.EqualTo(Operator.Subtract(a[i], b[i]))); } } - [Theory, Timeout(200)] + [Theory] public void CanSubtractScalarFromVector(TestVector testVector, T scalar) { - Vector vector = GetVector(testVector); + Vector vector = Get(testVector); Assume.That(vector.Count, Is.LessThan(100)); var hash = vector.GetHashCode(); @@ -215,8 +210,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests for (var i = 0; i < Math.Min(vector.Count, 20); i++) { - Assert.That(result1[i], Is.EqualTo(Subtract(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture)); - Assert.That(result2[i], Is.EqualTo(Subtract(vector[i], scalar)), i.ToString(CultureInfo.InvariantCulture)); + Assert.That(result1[i], Is.EqualTo(Operator.Subtract(vector[i], scalar))); + Assert.That(result2[i], Is.EqualTo(Operator.Subtract(vector[i], scalar))); } } } diff --git a/src/UnitTests/LinearAlgebraTests/VectorStorageCombinatorsTests.cs b/src/UnitTests/LinearAlgebraTests/VectorStorageCombinatorsTests.cs index bd84fa34..dea35fa7 100644 --- a/src/UnitTests/LinearAlgebraTests/VectorStorageCombinatorsTests.cs +++ b/src/UnitTests/LinearAlgebraTests/VectorStorageCombinatorsTests.cs @@ -39,40 +39,40 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests public class VectorStorageCombinatorsTests { [Theory] - public void MapToSkipZeros(VectorStorageType aType, VectorStorageType resultType) + public void MapToSkipZeros(TestVectorStorage aType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); - var result = Build.VectorStorage(resultType, 4); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); + var result = TestData.VectorStorage(resultType, 4); var expected = new DenseVectorStorage(4, new[] { -1.0, -2.0, 0.0, -4.0 }); a.MapTo(result, u => -u, Zeros.AllowSkip); Assert.That(result.Equals(expected)); } [Theory] - public void MapToForceIncludeZeros(VectorStorageType aType, VectorStorageType resultType) + public void MapToForceIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); - var result = Build.VectorStorage(resultType, 4); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); + var result = TestData.VectorStorage(resultType, 4); var expected = new DenseVectorStorage(4, new[] { 0.0, -1.0, 1.0, -3.0 }); a.MapTo(result, u => -u + 1.0, Zeros.Include); Assert.That(result.Equals(expected)); } [Theory] - public void MapToAutoIncludeZeros(VectorStorageType aType, VectorStorageType resultType) + public void MapToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); - var result = Build.VectorStorage(resultType, 4); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); + var result = TestData.VectorStorage(resultType, 4); var expected = new DenseVectorStorage(4, new[] { 0.0, -1.0, 1.0, -3.0 }); a.MapTo(result, u => -u + 1.0, Zeros.AllowSkip); Assert.That(result.Equals(expected)); } [Theory] - public void MapIndexedToSkipZeros(VectorStorageType aType, VectorStorageType resultType) + public void MapIndexedToSkipZeros(TestVectorStorage aType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); - var result = Build.VectorStorage(resultType, 4); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); + var result = TestData.VectorStorage(resultType, 4); var expected = new DenseVectorStorage(4, new[] { -1.0, -2.0, 0.0, -4.0 }); int badValueCount = 0; // one time is OK for zero-check a.MapIndexedTo(result, (i, u) => { if (a.At(i) != u) Interlocked.Increment(ref badValueCount); return -u; }, Zeros.AllowSkip); @@ -81,10 +81,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void MapIndexedToForceIncludeZeros(VectorStorageType aType, VectorStorageType resultType) + public void MapIndexedToForceIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); - var result = Build.VectorStorage(resultType, 4); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); + var result = TestData.VectorStorage(resultType, 4); var expected = new DenseVectorStorage(4, new[] { 0.0, -1.0, 1.0, -3.0 }); int badValueCount = 0; // one time is OK for zero-check a.MapIndexedTo(result, (i, u) => { if (a.At(i) != u) Interlocked.Increment(ref badValueCount); return -u + 1.0; }, Zeros.Include); @@ -93,10 +93,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void MapIndexedToAutoIncludeZeros(VectorStorageType aType, VectorStorageType resultType) + public void MapIndexedToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); - var result = Build.VectorStorage(resultType, 4); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0 }); + var result = TestData.VectorStorage(resultType, 4); var expected = new DenseVectorStorage(4, new[] { 0.0, -1.0, 1.0, -3.0 }); int badValueCount = 0; // one time is OK for zero-check a.MapIndexedTo(result, (i, u) => { if (a.At(i) != u) Interlocked.Increment(ref badValueCount); return -u + 1.0; }, Zeros.AllowSkip); @@ -105,52 +105,52 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests } [Theory] - public void Map2ToSkipZeros(VectorStorageType aType, VectorStorageType bType, VectorStorageType resultType) + public void Map2ToSkipZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); - var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); - var result = Build.VectorStorage(resultType, 6); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); + var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); + var result = TestData.VectorStorage(resultType, 6); var expected = new DenseVectorStorage(6, new[] { 12.0, 14.0, 13.0, 4.0, 0.0, 22.0 }); a.Map2To(result, b, (u, v) => u + v, Zeros.AllowSkip); Assert.That(result.Equals(expected)); } [Theory] - public void Map2ToForceIncludeZeros(VectorStorageType aType, VectorStorageType bType, VectorStorageType resultType) + public void Map2ToForceIncludeZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); - var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); - var result = Build.VectorStorage(resultType, 6); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); + var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); + var result = TestData.VectorStorage(resultType, 6); var expected = new DenseVectorStorage(6, new[] { 13.0, 15.0, 14.0, 5.0, 1.0, 23.0 }); a.Map2To(result, b, (u, v) => u + v + 1.0, Zeros.Include); Assert.That(result.Equals(expected)); } [Theory] - public void Map2ToAutoIncludeZeros(VectorStorageType aType, VectorStorageType bType, VectorStorageType resultType) + public void Map2ToAutoIncludeZeros(TestVectorStorage aType, TestVectorStorage bType, TestVectorStorage resultType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); - var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); - var result = Build.VectorStorage(resultType, 6); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); + var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); + var result = TestData.VectorStorage(resultType, 6); var expected = new DenseVectorStorage(6, new[] { 13.0, 15.0, 14.0, 5.0, 1.0, 23.0 }); a.Map2To(result, b, (u, v) => u + v + 1.0, Zeros.AllowSkip); Assert.That(result.Equals(expected)); } [Theory] - public void Fold2SkipZeros(VectorStorageType aType, VectorStorageType bType) + public void Fold2SkipZeros(TestVectorStorage aType, TestVectorStorage bType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); - var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); + var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); var result = a.Fold2(b, (acc, u, v) => acc + u + v, 0.0, Zeros.AllowSkip); Assert.That(result, Is.EqualTo(65)); } [Theory] - public void Fold2ForceIncludeZeros(VectorStorageType aType, VectorStorageType bType) + public void Fold2ForceIncludeZeros(TestVectorStorage aType, TestVectorStorage bType) { - var a = Build.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); - var b = Build.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); + var a = TestData.VectorStorage(aType, new[] { 1.0, 2.0, 0.0, 4.0, 0.0, 6.0 }); + var b = TestData.VectorStorage(bType, new[] { 11.0, 12.0, 13.0, 0.0, 0.0, 16.0 }); var result = a.Fold2(b, (acc, u, v) => acc + u + v + 1.0, 0.0, Zeros.Include); Assert.That(result, Is.EqualTo(71)); } diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index f7c303dd..102394a1 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -148,7 +148,6 @@ -