Browse Source

interpolation: minor refactoring

Signed-off-by: Christoph Ruegg <git@cdrnet.ch>
pull/2/head
Christoph Ruegg 17 years ago
parent
commit
5e0874c46e
  1. 11
      src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs
  2. 8
      src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs
  3. 2
      src/Managed/Interpolation/Algorithms/LinearSplineInterpolation.cs
  4. 1
      src/Managed/Interpolation/Interpolation.cs

11
src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs

@ -31,9 +31,9 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Gallio.Framework.Assertions; using Gallio.Framework.Assertions;
using Interpolation;
using MbUnit.Framework; using MbUnit.Framework;
using MbUnit.Framework.ContractVerifiers; using MbUnit.Framework.ContractVerifiers;
using Interpolation;
internal class InterpolationContract<TInterpolation> : AbstractContract internal class InterpolationContract<TInterpolation> : AbstractContract
where TInterpolation : IInterpolation where TInterpolation : IInterpolation
@ -51,7 +51,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
yield return CreateFactoryReturnsCorrectTypeTest("FactoryReturnsCorrectType"); yield return CreateFactoryReturnsCorrectTypeTest("FactoryReturnsCorrectType");
yield return CreateConsistentCapabilityBehaviorTest("ConsistentCapabilityBehavior"); yield return CreateConsistentCapabilityBehaviorTest("ConsistentCapabilityBehavior");
yield return CreateInterpolationMatchesNodePointsTest("InterpolationMatchesNodePoints"); yield return CreateInterpolationMatchesNodePointsTest("InterpolationMatchesNodePoints");
yield return CreateCanDealWithLinearSamplesTest("CanDealWithLinearSamples"); yield return CreateLinearBehaviorTest("LinearBehavior");
} }
private Test CreateFactoryReturnsCorrectTypeTest(string name) private Test CreateFactoryReturnsCorrectTypeTest(string name)
@ -135,7 +135,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
}); });
} }
private Test CreateCanDealWithLinearSamplesTest(string name) private Test CreateLinearBehaviorTest(string name)
{ {
return new TestCase(name, () => return new TestCase(name, () =>
{ {
@ -156,6 +156,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
values[i] = yOffset + i; values[i] = yOffset + i;
} }
var interpolation = Factory(points, values);
// build linear test vectors randomly between the sample points // build linear test vectors randomly between the sample points
double[] testPoints = new double[order + 1]; double[] testPoints = new double[order + 1];
double[] testValues = new double[order + 1]; double[] testValues = new double[order + 1];
@ -175,8 +177,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
} }
} }
var interpolation = Factory(points, values); // verify interpolation with test samples
for (int i = 0; i < testPoints.Length; i++) for (int i = 0; i < testPoints.Length; i++)
{ {
Assert.AreApproximatelyEqual( Assert.AreApproximatelyEqual(

8
src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs

@ -29,23 +29,23 @@
namespace MathNet.Numerics.UnitTests.InterpolationTests namespace MathNet.Numerics.UnitTests.InterpolationTests
{ {
using System; using System;
using MbUnit.Framework;
using MbUnit.Framework.ContractVerifiers;
using Interpolation; using Interpolation;
using Interpolation.Algorithms; using Interpolation.Algorithms;
using MbUnit.Framework;
using MbUnit.Framework.ContractVerifiers;
[TestFixture] [TestFixture]
public class InterpolationTest public class InterpolationTest
{ {
[VerifyContract] [VerifyContract]
public readonly IContract LinearSplineTests = new InterpolationContract<LinearSplineInterpolation>() public readonly IContract LinearSplineContractTests = new InterpolationContract<LinearSplineInterpolation>()
{ {
Factory = Interpolation.CreateLinearBetweenPoints, Factory = Interpolation.CreateLinearBetweenPoints,
Order = new[] { 2, 3, 6 } Order = new[] { 2, 3, 6 }
}; };
[VerifyContract] [VerifyContract]
public readonly IContract RationalPoleFreeTests = new InterpolationContract<RationalPoleFreeInterpolation>() public readonly IContract RationalPoleFreeContractTests = new InterpolationContract<RationalPoleFreeInterpolation>()
{ {
Factory = Interpolation.CreateRationalPoleFree, Factory = Interpolation.CreateRationalPoleFree,
Order = new[] { 1, 2, 6 } Order = new[] { 1, 2, 6 }

2
src/Managed/Interpolation/Algorithms/LinearSplineInterpolation.cs

@ -88,7 +88,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// Initialize the interpolation method with the given spline coefficients. /// Initialize the interpolation method with the given spline coefficients.
/// </summary> /// </summary>
/// <param name="samplePoints">Sample Points t</param> /// <param name="samplePoints">Sample Points t</param>
/// <param name="sampleValues">Sample Values x(samplePoints)</param> /// <param name="sampleValues">Sample Values x(t)</param>
public void Initialize( public void Initialize(
IList<double> samplePoints, IList<double> samplePoints,
IList<double> sampleValues) IList<double> sampleValues)

1
src/Managed/Interpolation/Interpolation.cs

@ -28,7 +28,6 @@
namespace MathNet.Numerics.Interpolation namespace MathNet.Numerics.Interpolation
{ {
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Algorithms; using Algorithms;

Loading…
Cancel
Save