@Test
  public void testTooLargeFirstStep()
      throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException,
          NoBracketingException {

    AdaptiveStepsizeIntegrator integ =
        new DormandPrince853Integrator(0, Double.POSITIVE_INFINITY, Double.NaN, Double.NaN);
    final double start = 0.0;
    final double end = 0.001;
    FirstOrderDifferentialEquations equations =
        new FirstOrderDifferentialEquations() {

          public int getDimension() {
            return 1;
          }

          public void computeDerivatives(double t, double[] y, double[] yDot) {
            Assert.assertTrue(t >= FastMath.nextAfter(start, Double.NEGATIVE_INFINITY));
            Assert.assertTrue(t <= FastMath.nextAfter(end, Double.POSITIVE_INFINITY));
            yDot[0] = -100.0 * y[0];
          }
        };

    integ.setStepSizeControl(0, 1.0, 1.0e-6, 1.0e-8);
    integ.integrate(equations, start, new double[] {1.0}, end, new double[1]);
  }
 public void testDimensionCheck() {
   try {
     TestProblem1 pb = new TestProblem1();
     AdaptiveStepsizeIntegrator integrator =
         new GraggBulirschStoerIntegrator(0.0, 1.0, 1.0e-10, 1.0e-10);
     integrator.integrate(
         pb, 0.0, new double[pb.getDimension() + 10], 1.0, new double[pb.getDimension() + 10]);
     fail("an exception should have been thrown");
   } catch (DerivativeException de) {
     fail("wrong exception caught");
   } catch (IntegratorException ie) {
   }
 }
  @Test
  public void testIncreasingTolerance()
      throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException,
          NoBracketingException {

    int previousCalls = Integer.MAX_VALUE;
    AdaptiveStepsizeIntegrator integ =
        new DormandPrince853Integrator(0, Double.POSITIVE_INFINITY, Double.NaN, Double.NaN);
    for (int i = -12; i < -2; ++i) {
      TestProblem1 pb = new TestProblem1();
      double minStep = 0;
      double maxStep = pb.getFinalTime() - pb.getInitialTime();
      double scalAbsoluteTolerance = FastMath.pow(10.0, i);
      double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
      integ.setStepSizeControl(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);

      TestProblemHandler handler = new TestProblemHandler(pb, integ);
      integ.addStepHandler(handler);
      integ.integrate(
          pb,
          pb.getInitialTime(),
          pb.getInitialState(),
          pb.getFinalTime(),
          new double[pb.getDimension()]);

      // the 1.3 factor is only valid for this test
      // and has been obtained from trial and error
      // there is no general relation between local and global errors
      Assert.assertTrue(handler.getMaximalValueError() < (1.3 * scalAbsoluteTolerance));
      Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);

      int calls = pb.getCalls();
      Assert.assertEquals(integ.getEvaluations(), calls);
      Assert.assertTrue(calls <= previousCalls);
      previousCalls = calls;
    }
  }