From 25f3b70a2faca0ce1b49bb956f6868c61954389d Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 26 Jul 2009 19:35:27 +0800 Subject: [PATCH] interpolation test: reorganized to support non-standard-parameter meta algorithms Signed-off-by: Christoph Ruegg --- .../InterpolationContract.cs | 21 ++++++-- .../InterpolationTests/InterpolationTest.cs | 52 +++++++++++++------ 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs b/src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs index c2877369..96c02f1f 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 NonStandardParameters { get; set; } public bool LinearBehavior { get; set; } public bool PolynomialBehavior { get; set; } public bool RationalBehavior { get; set; } @@ -51,24 +52,34 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests protected override IEnumerable GetContractVerificationTests() { + // Infrastructure Tests + yield return CreateFactoryReturnsCorrectTypeTest("FactoryReturnsCorrectType"); + yield return CreateConsistentCapabilityBehaviorTest("ConsistentCapabilityBehavior"); + yield return CreateInitChecksForNullTest("InitChecksForNull"); yield return CreateInitChecksForMatchingCountTest("InitChecksForMatchingCount"); - yield return CreateConstructorInitShortcutTest("ConstructorInitShortcut"); - yield return CreateConsistentCapabilityBehaviorTest("ConsistentCapabilityBehavior"); + + if (!NonStandardParameters) + { + yield return CreateConstructorInitShortcutTest("ConstructorInitShortcut"); + } + + // Numerics Behavior Tests + yield return CreateInterpolationMatchesNodePointsTest("InterpolationMatchesNodePoints"); - if (LinearBehavior) + if (LinearBehavior && !NonStandardParameters) { yield return CreateLinearBehaviorTest("LinearBehavior"); } - if (PolynomialBehavior) + if (PolynomialBehavior && !NonStandardParameters) { yield return CreatePolynomialBehaviorTest("PolynomialBehavior"); } - if (RationalBehavior) + if (RationalBehavior && !NonStandardParameters) { yield return CreateRationalBehaviorTest("RationalBehavior"); } diff --git a/src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs b/src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs index bdf355be..686a50f7 100644 --- a/src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs +++ b/src/Managed.UnitTests/InterpolationTests/InterpolationTest.cs @@ -37,44 +37,66 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests [TestFixture] public class InterpolationTest { + // Direct Algorithms (without precomputations) + [VerifyContract] - public readonly IContract LinearSplineContractTests = new InterpolationContract() + public readonly IContract NevillePolynomialContractTests = new InterpolationContract() { - Factory = Interpolate.LinearBetweenPoints, - Order = new[] { 2, 3, 6 }, + Factory = (t, x) => new NevillePolynomialInterpolation(t, x), + Order = new[] { 1, 2, 6 }, LinearBehavior = true, - PolynomialBehavior = false, + PolynomialBehavior = true, RationalBehavior = false }; [VerifyContract] - public readonly IContract FloaterHormannRationalContractTests = new InterpolationContract() + public readonly IContract BulirschStoerRationalContractTests = new InterpolationContract() { - Factory = Interpolate.RationalWithoutPoles, + Factory = Interpolate.RationalWithPoles, Order = new[] { 1, 2, 6 }, - LinearBehavior = true, + LinearBehavior = false, PolynomialBehavior = true, RationalBehavior = true }; + // Barycentric Algorithms + [VerifyContract] - public readonly IContract NevillePolynomialContractTests = new InterpolationContract() + public readonly IContract BarycentricContractTests = new InterpolationContract() { - Factory = (t, x) => new NevillePolynomialInterpolation(t, x), + Factory = (t, x) => new BarycentricInterpolation(t, x, FloaterHormannRationalInterpolation.EvaluateBarycentricWeights(t, x, 2)), Order = new[] { 1, 2, 6 }, - LinearBehavior = true, - PolynomialBehavior = true, - RationalBehavior = false + NonStandardParameters = true, }; [VerifyContract] - public readonly IContract BulirschStoerRationalContractTests = new InterpolationContract() + public readonly IContract FloaterHormannRationalContractTests = new InterpolationContract() { - Factory = Interpolate.RationalWithPoles, + Factory = Interpolate.RationalWithoutPoles, Order = new[] { 1, 2, 6 }, - LinearBehavior = false, + LinearBehavior = true, PolynomialBehavior = true, RationalBehavior = true }; + + // Spline Algorithms + + [VerifyContract] + public readonly IContract SplineContractTests = new InterpolationContract() + { + Factory = (t, x) => new SplineInterpolation(t, LinearSplineInterpolation.EvaluateSplineCoefficients(t, x)), + Order = new[] { 1, 2, 6 }, + NonStandardParameters = true, + }; + + [VerifyContract] + public readonly IContract LinearSplineContractTests = new InterpolationContract() + { + Factory = Interpolate.LinearBetweenPoints, + Order = new[] { 2, 3, 6 }, + LinearBehavior = true, + PolynomialBehavior = false, + RationalBehavior = false + }; } }