final double[][] yValues = new double[][] { {1., 1., 2., 4., 4., 2., 1., 1. }, {10., 10., 6., 4., 4., 6., 10., 10. } };
PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
PiecewisePolynomialResult result = interp.interpolate(xValues, yValues);
PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();
PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingCubicSplineInterpolator(interp);
PiecewisePolynomialResult resultPos = interpPos.interpolate(xValues, yValues);
// System.out.println(resultPos.getCoefMatrix());
assertEquals(resultPos.getDimensions(), result.getDimensions());
assertEquals(resultPos.getNumberOfIntervals(), result.getNumberOfIntervals());
assertEquals(resultPos.getOrder(), result.getOrder());
assertTrue(function.evaluate(resultPos, 4.5).getData()[0] - function.evaluate(resultPos, 4).getData()[0] >= 0.);
assertTrue(function.evaluate(resultPos, 4.5).getData()[0] - function.evaluate(resultPos, 5).getData()[0] >= 0.);
assertTrue(function.evaluate(resultPos, 4.5).getData()[1] - function.evaluate(resultPos, 4).getData()[1] <= 0.);
assertTrue(function.evaluate(resultPos, 4.5).getData()[1] - function.evaluate(resultPos, 5).getData()[1] <= 0.);
final int nKeys = 41;
double key0 = 1.;
for (int i = 1; i < nKeys; ++i) {
final double key = 1. + 3. / (nKeys - 1) * i;
assertTrue(function.evaluate(resultPos, key).getData()[0] - function.evaluate(resultPos, key0).getData()[0] >= 0.);
// System.out.println(key + "\t" + function.evaluate(result, key).getData()[0] + "\t" + function.evaluate(resultPos, key).getData()[0]);
key0 = 1. + 3. / (nKeys - 1) * i;
}
key0 = 1.;
for (int i = 1; i < nKeys; ++i) {
final double key = 1. + 3. / (nKeys - 1) * i;
assertTrue(function.evaluate(resultPos, key).getData()[1] - function.evaluate(resultPos, key0).getData()[1] <= 0.);
// System.out.println(key + "\t" + function.evaluate(result, key).getData()[1] + "\t" + function.evaluate(resultPos, key).getData()[1]);
key0 = 1. + 3. / (nKeys - 1) * i;
}
key0 = 5.;
for (int i = 1; i < nKeys; ++i) {
final double key = 5. + 3. / (nKeys - 1) * i;
assertTrue(function.evaluate(resultPos, key).getData()[0] - function.evaluate(resultPos, key0).getData()[0] <= 0.);
// System.out.println(key + "\t" + function.evaluate(result, key).getData()[0] + "\t" + function.evaluate(resultPos, key).getData()[0]);
key0 = 5. + 3. / (nKeys - 1) * i;
}
key0 = 5.;
for (int i = 1; i < nKeys; ++i) {
final double key = 5. + 3. / (nKeys - 1) * i;
assertTrue(function.evaluate(resultPos, key).getData()[1] - function.evaluate(resultPos, key0).getData()[1] >= 0.);
// System.out.println(key + "\t" + function.evaluate(result, key).getData()[1] + "\t" + function.evaluate(resultPos, key).getData()[1]);
key0 = 5. + 3. / (nKeys - 1) * i;
}
}