diff --git a/src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs b/src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs index 83985501..92bd04ed 100644 --- a/src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs +++ b/src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs @@ -40,6 +40,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests { public Func, IList, 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 { -2.0, -1.0, 0.0, 1.0, 2.0 }; + var values = new List { 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"); + }); + } } } diff --git a/src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs b/src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs index 03204ac5..b7d36a4e 100644 --- a/src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs +++ b/src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs @@ -41,21 +41,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests public readonly IContract LinearSplineContractTests = new InterpolationContract() { Factory = Interpolation.CreateLinearBetweenPoints, - Order = new[] { 2, 3, 6 } + Order = new[] { 2, 3, 6 }, + PolynomialBehavior = false }; [VerifyContract] public readonly IContract RationalPoleFreeContractTests = new InterpolationContract() { Factory = Interpolation.CreateRationalPoleFree, - Order = new[] { 1, 2, 6 } + Order = new[] { 1, 2, 6 }, + PolynomialBehavior = true }; [VerifyContract] public readonly IContract NevillePolynomialContractTests = new InterpolationContract() { Factory = (t, x) => new NevillePolynomialInterpolation(t, x), - Order = new[] { 1, 2, 6 } + Order = new[] { 1, 2, 6 }, + PolynomialBehavior = true }; } }