@Test
public void testValues() {
PolynomialSplineFunction spline =
new PolynomialSplineFunction(knots, polynomials);
UnivariateFunction dSpline = spline.derivative();
/**
* interior points -- spline value at x should equal p(x - knot)
* where knot is the largest knot point less than or equal to x and p
* is the polynomial defined over the knot segment to which x belongs.
*/
double x = -1;
int index = 0;
for (int i = 0; i < 10; i++) {
x+=0.25;
index = findKnot(knots, x);
Assert.assertEquals("spline function evaluation failed for x=" + x,
polynomials[index].value(x - knots[index]), spline.value(x), tolerance);
Assert.assertEquals("spline derivative evaluation failed for x=" + x,
dp.value(x - knots[index]), dSpline.value(x), tolerance);
}
// knot points -- centering should zero arguments
for (int i = 0; i < 3; i++) {
Assert.assertEquals("spline function evaluation failed for knot=" + knots[i],
polynomials[i].value(0), spline.value(knots[i]), tolerance);
Assert.assertEquals("spline function evaluation failed for knot=" + knots[i],
dp.value(0), dSpline.value(knots[i]), tolerance);
}
try { //outside of domain -- under min
x = spline.value(-1.5);
Assert.fail("Expecting OutOfRangeException");