diff --git a/src/UnitTests/IntegralTransformsTests/FourierTest.cs b/src/UnitTests/IntegralTransformsTests/FourierTest.cs index bb5221a4..265b341d 100644 --- a/src/UnitTests/IntegralTransformsTests/FourierTest.cs +++ b/src/UnitTests/IntegralTransformsTests/FourierTest.cs @@ -32,6 +32,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests using MbUnit.Framework; using IntegralTransforms; using IntegralTransforms.Algorithms; + using Sampling; [TestFixture] public class FourierTest @@ -39,7 +40,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests [Test] public void NaiveTransformsRealSineCorrectly() { - var samples = SampleProvider.ProvideComplexRealSine(16); + var samples = Sample.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 16); // real-odd transforms to imaginary odd var dft = new DiscreteFourierTransform(); diff --git a/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs b/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs index 259a4fc9..784bdccd 100644 --- a/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs +++ b/src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs @@ -32,6 +32,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests using IntegralTransforms; using IntegralTransforms.Algorithms; using MbUnit.Framework; + using Sampling; [TestFixture] public class MatchingNaiveTransformTest @@ -58,7 +59,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests public void FourierRadix2MatchesNaiveOnRealSine(FourierOptions options) { var dft = new DiscreteFourierTransform(); - var samples = SampleProvider.ProvideComplexRealSine(16); + var samples = Sample.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 16); VerifyMatchesNaiveComplex( samples, @@ -102,7 +103,7 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests public void FourierBluesteinMatchesNaiveOnRealSineNonPowerOfTwo(FourierOptions options) { var dft = new DiscreteFourierTransform(); - var samples = SampleProvider.ProvideComplexRealSine(14); + var samples = Sample.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 14); VerifyMatchesNaiveComplex( samples, diff --git a/src/UnitTests/IntegralTransformsTests/SampleProvider.cs b/src/UnitTests/IntegralTransformsTests/SampleProvider.cs index e2ee1cc0..b1857908 100644 --- a/src/UnitTests/IntegralTransformsTests/SampleProvider.cs +++ b/src/UnitTests/IntegralTransformsTests/SampleProvider.cs @@ -57,17 +57,5 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests return samples; } - - internal static Complex[] ProvideComplexRealSine(int count) - { - double halfPeriod = count / 2.0; - var samples = new Complex[count]; - for (int i = 0; i < samples.Length; i++) - { - samples[i] = Math.Sin(i * Constants.Pi / halfPeriod); - } - - return samples; - } } -} +} \ No newline at end of file diff --git a/src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs b/src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs index 26f1ecbc..ab4ff573 100644 --- a/src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs +++ b/src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs @@ -33,6 +33,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests using Interpolation; using MbUnit.Framework; using MbUnit.Framework.ContractVerifiers; + using Sampling; internal class InterpolationFunctionalContract : AbstractContract where TInterpolation : IInterpolation @@ -94,8 +95,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests "LinearBehavior", () => { - const double yOffset = 2.0; - const double xOffset = 4.0; + const double YOffset = 2.0; + const double XOffset = 4.0; var random = new Random(); int[] orders = { MinimumSampleCount, MinimumSampleCount + 1, MinimumSampleCount + 5 }; @@ -109,8 +110,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests var values = new double[order]; for (int i = 0; i < points.Length; i++) { - points[i] = xOffset + i; - values[i] = yOffset + i; + points[i] = XOffset + i; + values[i] = YOffset + i; } var interpolation = Factory(points, values); @@ -120,17 +121,17 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests var testValues = new double[order + 1]; if (order == 1) { - testPoints[0] = xOffset - random.NextDouble(); - testPoints[1] = xOffset + random.NextDouble(); - testValues[0] = testValues[1] = yOffset; + testPoints[0] = XOffset - random.NextDouble(); + testPoints[1] = XOffset + random.NextDouble(); + testValues[0] = testValues[1] = YOffset; } else { for (int i = 0; i < testPoints.Length; i++) { double z = (i - 1) + random.NextDouble(); - testPoints[i] = xOffset + z; - testValues[i] = yOffset + z; + testPoints[i] = XOffset + z; + testValues[i] = YOffset + z; } } @@ -176,8 +177,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests "RationalBehavior", () => { - double[] points, values; - SampleProvider.Equidistant(t => 1 / (1 + (t * t)), -5.0, 5.0, 41, out points, out values); + double[] points; + double[] values = Sample.EquidistantInterval(t => 1 / (1 + (t * t)), -5.0, 5.0, 41, out points); var interpolation = Factory(points, values); for (int i = 0; i < points.Length; i++) @@ -189,8 +190,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests "Match on knots"); } - double[] testPoints, testValues; - SampleProvider.Equidistant(t => 1 / (1 + (t * t)), -5.0, 5.0, 81, out testPoints, out testValues); + double[] testPoints; + double[] testValues = Sample.EquidistantInterval(t => 1 / (1 + (t * t)), -5.0, 5.0, 81, out testPoints); for (int i = 0; i < testPoints.Length; i++) { diff --git a/src/UnitTests/InterpolationTests/InterpolationInfrastuctureTest.cs b/src/UnitTests/InterpolationTests/InterpolationInfrastuctureTest.cs index 31b0722c..8904a9fe 100644 --- a/src/UnitTests/InterpolationTests/InterpolationInfrastuctureTest.cs +++ b/src/UnitTests/InterpolationTests/InterpolationInfrastuctureTest.cs @@ -34,6 +34,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests using Interpolation.Algorithms; using MbUnit.Framework; using MbUnit.Framework.ContractVerifiers; + using Sampling; [TestFixture] public class InterpolationInfrastuctureTest @@ -54,8 +55,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new NevillePolynomialInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)) + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)) } }; @@ -73,11 +74,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new BulirschStoerRationalInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)), () => Interpolate.RationalWithPoles( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)) + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)) } }; @@ -97,13 +98,13 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new BarycentricInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5), - SampleProvider.LinearEquidistant(10, 1, 0.1)), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10), + Sample.EquidistantStartingAt(t => t, 1, 0.1, 10)), () => new BarycentricInterpolation( - SampleProvider.LinearEquidistant(10, 5, -1), - SampleProvider.LinearEquidistant(10, -2, 0.5), - SampleProvider.LinearEquidistant(10, 1, 0.1)) + Sample.EquidistantStartingAt(t => t, 5, -1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10), + Sample.EquidistantStartingAt(t => t, 1, 0.1, 10)) } }; @@ -121,18 +122,18 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new FloaterHormannRationalInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)), () => new FloaterHormannRationalInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10), 5), () => Interpolate.RationalWithoutPoles( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)), () => Interpolate.Common( - SampleProvider.LinearEquidistant(10, 5, -1), - SampleProvider.LinearEquidistant(10, -2, 0.5)) + Sample.EquidistantStartingAt(t => t, 5, -1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)) } }; @@ -150,15 +151,15 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new EquidistantPolynomialInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)), () => new EquidistantPolynomialInterpolation( - SampleProvider.LinearEquidistant(10, 5, -1), - SampleProvider.LinearEquidistant(10, -2, 0.5)), + Sample.EquidistantStartingAt(t => t, 5, -1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)), () => new EquidistantPolynomialInterpolation( -5, 4, - SampleProvider.LinearEquidistant(10, -2, 0.5)) + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)) } }; @@ -178,18 +179,18 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new SplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(4 * (10 - 1), -2, 0.5)), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 4 * (10 - 1))), () => new SplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), AkimaSplineInterpolation.EvaluateSplineCoefficients( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5))), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10))), () => new SplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), CubicSplineInterpolation.EvaluateSplineCoefficients( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10), SplineBoundaryCondition.Natural, 1.0, SplineBoundaryCondition.Natural, @@ -211,9 +212,9 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new CubicHermiteSplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5), - SampleProvider.LinearEquidistant(10, 1, 0.1)) + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10), + Sample.EquidistantStartingAt(t => t, 1, 0.1, 10)) } }; @@ -231,11 +232,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new LinearSplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)), () => Interpolate.LinearBetweenPoints( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)) + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)) } }; @@ -253,32 +254,32 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new CubicSplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)), () => new CubicSplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10), SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0), () => new CubicSplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10), SplineBoundaryCondition.Natural, 1.0, SplineBoundaryCondition.Natural, -1.0), () => new CubicSplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5), + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10), SplineBoundaryCondition.ParabolicallyTerminated, 1.0, SplineBoundaryCondition.ParabolicallyTerminated, -1.0), () => new CubicSplineInterpolation( - SampleProvider.LinearEquidistant(2, -5, 1), - SampleProvider.LinearEquidistant(2, -2, 0.5), + Sample.EquidistantStartingAt(t => t, -5, 1, 2), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 2), SplineBoundaryCondition.ParabolicallyTerminated, 1.0, SplineBoundaryCondition.ParabolicallyTerminated, @@ -300,8 +301,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests new Expression>[] { () => new AkimaSplineInterpolation( - SampleProvider.LinearEquidistant(10, -5, 1), - SampleProvider.LinearEquidistant(10, -2, 0.5)) + Sample.EquidistantStartingAt(t => t, -5, 1, 10), + Sample.EquidistantStartingAt(t => t, -2, 0.5, 10)) } }; @@ -340,4 +341,4 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests 0)); } } -} +} \ No newline at end of file diff --git a/src/UnitTests/InterpolationTests/SampleProvider.cs b/src/UnitTests/InterpolationTests/SampleProvider.cs deleted file mode 100644 index abd8903d..00000000 --- a/src/UnitTests/InterpolationTests/SampleProvider.cs +++ /dev/null @@ -1,81 +0,0 @@ -// -// Math.NET Numerics, part of the Math.NET Project -// http://mathnet.opensourcedotnet.info -// -// Copyright (c) 2009 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.InterpolationTests -{ - using System; - - internal static class SampleProvider - { - internal static double[] LinearEquidistant(int count, double start, double step) - { - var samples = new double[count]; - var nextValue = start; - - for (int i = 0; i < samples.Length; i++) - { - samples[i] = nextValue; - nextValue += step; - } - - return samples; - } - - internal static void Equidistant( - Func f, - double start, - double stop, - int samples, - out double[] points, - out double[] values) - { - points = new double[samples]; - values = new double[samples]; - - if (samples == 0) - { - return; - } - - if (samples == 1) - { - double t = points[0] = 0.5 * (start + stop); - values[0] = f(t); - return; - } - - double step = (stop - start) / (samples - 1); - for (int i = 0; i < points.Length; i++) - { - double t = start + (i * step); - points[i] = t; - values[i] = f(t); - } - } - } -} diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index 7a64284b..ccaeee0b 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -81,7 +81,6 @@ -