/**
   * Test of interpolator for the sine function.
   *
   * <p>|sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
   */
  @Test
  public void testSinFunction() {
    UnivariateFunction f = new Sin();
    UnivariateInterpolator interpolator = new DividedDifferenceInterpolator();
    double x[], y[], z, expected, result, tolerance;

    // 6 interpolating points on interval [0, 2*PI]
    int n = 6;
    double min = 0.0, max = 2 * FastMath.PI;
    x = new double[n];
    y = new double[n];
    for (int i = 0; i < n; i++) {
      x[i] = min + i * (max - min) / n;
      y[i] = f.value(x[i]);
    }
    double derivativebound = 1.0;
    UnivariateFunction p = interpolator.interpolate(x, y);

    z = FastMath.PI / 4;
    expected = f.value(z);
    result = p.value(z);
    tolerance = FastMath.abs(derivativebound * partialerror(x, z));
    Assert.assertEquals(expected, result, tolerance);

    z = FastMath.PI * 1.5;
    expected = f.value(z);
    result = p.value(z);
    tolerance = FastMath.abs(derivativebound * partialerror(x, z));
    Assert.assertEquals(expected, result, tolerance);
  }
  /** Test of parameters for the interpolator. */
  @Test
  public void testParameters() {
    UnivariateInterpolator interpolator = new DividedDifferenceInterpolator();

    try {
      // bad abscissas array
      double x[] = {1.0, 2.0, 2.0, 4.0};
      double y[] = {0.0, 4.0, 4.0, 2.5};
      UnivariateFunction p = interpolator.interpolate(x, y);
      p.value(0.0);
      Assert.fail("Expecting NonMonotonicSequenceException - bad abscissas array");
    } catch (NonMonotonicSequenceException ex) {
      // expected
    }
  }