Browse Source

interpolation test: exception case testing (code coverage)

Signed-off-by: Christoph Ruegg <git@cdrnet.ch>
pull/2/head
Christoph Ruegg 17 years ago
parent
commit
e875e3232c
  1. 53
      src/Managed.UnitTests/InterpolationTests/InterpolationContract.cs
  2. 5
      src/Managed/Interpolation/Algorithms/FloaterHormannRationalInterpolation.cs

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

@ -51,6 +51,9 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
protected override IEnumerable<Test> GetContractVerificationTests()
{
yield return CreateFactoryReturnsCorrectTypeTest("FactoryReturnsCorrectType");
yield return CreateInitChecksForNullTest("InitChecksForNull");
yield return CreateInitChecksForMatchingCountTest("InitChecksForMatchingCount");
yield return CreateConstructorInitShortcutTest("ConstructorInitShortcut");
yield return CreateConsistentCapabilityBehaviorTest("ConsistentCapabilityBehavior");
yield return CreateInterpolationMatchesNodePointsTest("InterpolationMatchesNodePoints");
yield return CreateLinearBehaviorTest("LinearBehavior");
@ -89,6 +92,56 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
});
}
private Test CreateInitChecksForNullTest(string name)
{
return new TestCase(name, () =>
{
var points = new List<double> { 1, 2, 3, 4, 5 };
var values = new List<double> { 10, 20, 30, 40, 50 };
Assert.DoesNotThrow(() => Factory(points, values));
Assert.Throws(typeof(ArgumentNullException), () => Factory(points, null));
Assert.Throws(typeof(ArgumentNullException), () => Factory(null, values));
Assert.Throws(typeof(ArgumentNullException), () => Factory(null, null));
});
}
private Test CreateInitChecksForMatchingCountTest(string name)
{
return new TestCase(name, () =>
{
var points = new List<double> { 1, 2, 3, 4, 5 };
var valuesOk = new List<double> { 10, 20, 30, 40, 50 };
var valuesFail1 = new List<double> { 10, 20, 30, 40 };
var valuesFail2 = new List<double> { 10, 20, 30, 40, 50, 60 };
Assert.DoesNotThrow(() => Factory(points, valuesOk));
Assert.Throws(typeof(ArgumentException), () => Factory(points, valuesFail1));
Assert.Throws(typeof(ArgumentException), () => Factory(points, valuesFail2));
});
}
private Test CreateConstructorInitShortcutTest(string name)
{
return new TestCase(name, () =>
{
var points = new List<double> { 1, 2, 3, 4, 5 };
var values = new List<double> { 10, 20, 30, 40, 50 };
var ctor = typeof(TInterpolation).GetConstructor(
new[] { typeof (IList<double>), typeof (IList<double>) }
);
var interpolation = (IInterpolation)ctor.Invoke(
new[] { points, values }
);
Assert.AreApproximatelyEqual(20, interpolation.Interpolate(2), 1e-12);
});
}
private Test CreateConsistentCapabilityBehaviorTest(string name)
{
return new TestCase(name, () =>

5
src/Managed/Interpolation/Algorithms/FloaterHormannRationalInterpolation.cs

@ -96,6 +96,11 @@ namespace MathNet.Numerics.Interpolation.Algorithms
IList<double> samplePoints,
IList<double> sampleValues)
{
if (null == samplePoints)
{
throw new ArgumentNullException("samplePoints");
}
Initialize(samplePoints, sampleValues, Math.Min(3, samplePoints.Count - 1));
}

Loading…
Cancel
Save