Browse Source

interpolation test: added polynomial behavior contract

Signed-off-by: Christoph Ruegg <git@cdrnet.ch>
pull/36/head
Christoph Ruegg 17 years ago
parent
commit
e3e646e840
  1. 28
      src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs
  2. 9
      src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs

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

@ -40,6 +40,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
{
public Func<IList<double>, IList<double>, IInterpolation> Factory { get; set; }
public int[] Order { get; set; }
public bool PolynomialBehavior { get; set; }
public InterpolationContract()
{
@ -52,6 +53,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
yield return CreateConsistentCapabilityBehaviorTest("ConsistentCapabilityBehavior");
yield return CreateInterpolationMatchesNodePointsTest("InterpolationMatchesNodePoints");
yield return CreateLinearBehaviorTest("LinearBehavior");
if (PolynomialBehavior)
{
yield return CreatePolynomialBehaviorTest("PolynomialBehavior");
}
}
private Test CreateFactoryReturnsCorrectTypeTest(string name)
@ -188,5 +194,27 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
}
});
}
private Test CreatePolynomialBehaviorTest(string name)
{
return new TestCase(name, () =>
{
var points = new List<double> { -2.0, -1.0, 0.0, 1.0, 2.0 };
var values = new List<double> { 1.0, 2.0, -1.0, 0.0, 1.0 };
var interpolation = Factory(points, values);
// Maple: "with(CurveFitting);"
// Maple: "PolynomialInterpolation([[-2,1],[-1,2],[0,-1],[1,0],[2,1]], x);"
Assert.AreApproximatelyEqual(-4.5968, interpolation.Interpolate(-2.4), 1e-6, "A -2.4");
Assert.AreApproximatelyEqual(1.65395, interpolation.Interpolate(-0.9), 1e-6, "A -0.9");
Assert.AreApproximatelyEqual(0.21875, interpolation.Interpolate(-0.5), 1e-6, "A -0.5");
Assert.AreApproximatelyEqual(-0.84205, interpolation.Interpolate(-0.1), 1e-6, "A -0.1");
Assert.AreApproximatelyEqual(-1.10805, interpolation.Interpolate(0.1), 1e-6, "A 0.1");
Assert.AreApproximatelyEqual(-1.1248, interpolation.Interpolate(0.4), 1e-6, "A 0.4");
Assert.AreApproximatelyEqual(0.5392, interpolation.Interpolate(1.2), 1e-6, "A 1.2");
Assert.AreApproximatelyEqual(-4431.0, interpolation.Interpolate(10.0), 1e-6, "A 10.0");
Assert.AreApproximatelyEqual(-5071.0, interpolation.Interpolate(-10.0), 1e-6, "A -10.0");
});
}
}
}

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

@ -41,21 +41,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
public readonly IContract LinearSplineContractTests = new InterpolationContract<LinearSplineInterpolation>()
{
Factory = Interpolation.CreateLinearBetweenPoints,
Order = new[] { 2, 3, 6 }
Order = new[] { 2, 3, 6 },
PolynomialBehavior = false
};
[VerifyContract]
public readonly IContract RationalPoleFreeContractTests = new InterpolationContract<RationalPoleFreeInterpolation>()
{
Factory = Interpolation.CreateRationalPoleFree,
Order = new[] { 1, 2, 6 }
Order = new[] { 1, 2, 6 },
PolynomialBehavior = true
};
[VerifyContract]
public readonly IContract NevillePolynomialContractTests = new InterpolationContract<NevillePolynomialInterpolation>()
{
Factory = (t, x) => new NevillePolynomialInterpolation(t, x),
Order = new[] { 1, 2, 6 }
Order = new[] { 1, 2, 6 },
PolynomialBehavior = true
};
}
}

Loading…
Cancel
Save