nus-yam/ex-repair huggingface dataset:
Program: 57434
Project: 57434
Buggy source:
/** 
 * Get the current solution.
 * @return current solution
 */
protected RealPointValuePair getSolution(){
  double[] coefficients=new double[getOriginalNumDecisionVariables()];
  Integer basicRow=getBasicRow(getNumObjectiveFunctions() + getOriginalNumDecisionVariables());
  double mostNegative=basicRow == null ? 0 : getEntry(basicRow,getRhsOffset());
  Set<Integer> basicRows=new HashSet<Integer>();
  for (int i=0; i < coefficients.length; i++) {
    basicRow=getBasicRow(getNumObjectiveFunctions() + i);
    if (basicRows.contains(basicRow)) {
      coefficients[i]=0;
    }
 else {
      basicRows.add(basicRow);
      coefficients[i]=(basicRow == null ? 0 : getEntry(basicRow,getRhsOffset())) - (restrictToNonNegative ? 0 : mostNegative);
    }
  }
  return new RealPointValuePair(coefficients,f.getValue(coefficients));
}

Fixed version (ground truth):
/** 
 * Get the current solution.
 * @return current solution
 */
protected RealPointValuePair getSolution(){
  double[] coefficients=new double[getOriginalNumDecisionVariables()];
  Integer negativeVarBasicRow=getBasicRowForSolution(getNegativeDecisionVariableOffset());
  double mostNegative=negativeVarBasicRow == null ? 0 : getEntry(negativeVarBasicRow,getRhsOffset());
  Set<Integer> basicRows=new HashSet<Integer>();
  for (int i=0; i < coefficients.length; i++) {
    Integer basicRow=getBasicRowForSolution(getNumObjectiveFunctions() + i);
    if (basicRows.contains(basicRow)) {
      coefficients[i]=0;
    }
 else {
      basicRows.add(basicRow);
      coefficients[i]=(basicRow == null ? 0 : getEntry(basicRow,getRhsOffset())) - (restrictToNonNegative ? 0 : mostNegative);
    }
  }
  return new RealPointValuePair(coefficients,f.getValue(coefficients));
}
Program: 57435
Project: 57435
Buggy source:
/** 
 * Checks whether the given column is basic.
 * @param col index of the column to check
 * @return the row that the variable is basic in.  null if the column is not basic
 */
private Integer getBasicRow(final int col){
  Integer row=null;
  for (int i=getNumObjectiveFunctions(); i < getHeight(); i++) {
    if (MathUtils.equals(getEntry(i,col),1.0,epsilon) && (row == null)) {
      row=i;
    }
 else     if (!MathUtils.equals(getEntry(i,col),0.0,epsilon)) {
      return null;
    }
  }
  return row;
}

Fixed version (ground truth):
/** 
 * Checks whether the given column is basic.
 * @param col index of the column to check
 * @return the row that the variable is basic in.  null if the column is not basic
 */
private Integer getBasicRow(final int col,boolean ignoreObjectiveRows){
  Integer row=null;
  int start=ignoreObjectiveRows ? getNumObjectiveFunctions() : 0;
  for (int i=start; i < getHeight(); i++) {
    if (MathUtils.equals(getEntry(i,col),1.0,epsilon) && (row == null)) {
      row=i;
    }
 else     if (!MathUtils.equals(getEntry(i,col),0.0,epsilon)) {
      return null;
    }
  }
  return row;
}
Program: 57436
Project: 57436
Buggy source:
/** 
 * Get all the optima found during the last call to   {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize}. <p>The optimizer stores all the optima found during a set of restarts. The   {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize} method returns the best point only. Thismethod returns all the points found at the end of each starts, including the best one already returned by the  {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize}method. </p> <p> The returned array as one element for each start as specified in the constructor. It is ordered with the results from the runs that did converge first, sorted from best to worst objective value (i.e in ascending order if minimizing and in descending order if maximizing), followed by and null elements corresponding to the runs that did not converge. This means all elements will be null if the   {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize} method did throw a {@link ConvergenceException ConvergenceException}). This also means that if the first element is non null, it is the best point found across all starts.</p>
 * @return array containing the optima
 * @exception IllegalStateException if {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize} has not been called
 */
public double[] getOptima() throws IllegalStateException {
  if (optima == null) {
    throw MathRuntimeException.createIllegalStateException("String_Node_Str");
  }
  return optima.clone();
}

Fixed version (ground truth):
/** 
 * Get all the optima found during the last call to   {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize}. <p>The optimizer stores all the optima found during a set of restarts. The   {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize} method returns the best point only. Thismethod returns all the points found at the end of each starts, including the best one already returned by the  {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize}method. </p> <p> The returned array as one element for each start as specified in the constructor. It is ordered with the results from the runs that did converge first, sorted from best to worst objective value (i.e in ascending order if minimizing and in descending order if maximizing), followed by Double.NaN elements corresponding to the runs that did not converge. This means all elements will be NaN if the   {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize} method did throw a {@link ConvergenceException ConvergenceException}). This also means that if the first element is not NaN, it is the best point found across all starts.</p>
 * @return array containing the optima
 * @exception IllegalStateException if {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize} has not been called
 * @see #getOptimaValues()
 */
public double[] getOptima() throws IllegalStateException {
  if (optima == null) {
    throw MathRuntimeException.createIllegalStateException("String_Node_Str");
  }
  return optima.clone();
}
Program: 57437
Project: 57437
Buggy source:
/** 
 * Clear the array, reset the size to the initialCapacity and the number  of elements to zero.
 */
public synchronized void clear(){
  numElements=0;
  internalArray=new double[initialCapacity];
}

Fixed version (ground truth):
/** 
 * Clear the array, reset the size to the initialCapacity and the number  of elements to zero.
 */
public synchronized void clear(){
  numElements=0;
  startIndex=0;
  internalArray=new double[initialCapacity];
}
Program: 57438
Project: 57438
Buggy source:
/** 
 * Build an integrator with the given stepsize bounds. The default step handler does nothing.
 * @param name name of the method
 * @param minStep minimal step (must be positive even for backwardintegration), the last step can be smaller than this
 * @param maxStep maximal step (must be positive even for backwardintegration)
 * @param vecAbsoluteTolerance allowed absolute error
 * @param vecRelativeTolerance allowed relative error
 */
public AdaptiveStepsizeIntegrator(final String name,final double minStep,final double maxStep,final double[] vecAbsoluteTolerance,final double[] vecRelativeTolerance){
  super(name);
  this.minStep=minStep;
  this.maxStep=maxStep;
  this.initialStep=-1.0;
  this.scalAbsoluteTolerance=0;
  this.scalRelativeTolerance=0;
  this.vecAbsoluteTolerance=vecAbsoluteTolerance;
  this.vecRelativeTolerance=vecRelativeTolerance;
  resetInternalState();
}

Fixed version (ground truth):
/** 
 * Build an integrator with the given stepsize bounds. The default step handler does nothing.
 * @param name name of the method
 * @param minStep minimal step (must be positive even for backwardintegration), the last step can be smaller than this
 * @param maxStep maximal step (must be positive even for backwardintegration)
 * @param vecAbsoluteTolerance allowed absolute error
 * @param vecRelativeTolerance allowed relative error
 */
public AdaptiveStepsizeIntegrator(final String name,final double minStep,final double maxStep,final double[] vecAbsoluteTolerance,final double[] vecRelativeTolerance){
  super(name);
  this.minStep=minStep;
  this.maxStep=maxStep;
  this.initialStep=-1.0;
  this.scalAbsoluteTolerance=0;
  this.scalRelativeTolerance=0;
  this.vecAbsoluteTolerance=vecAbsoluteTolerance.clone();
  this.vecRelativeTolerance=vecRelativeTolerance.clone();
  resetInternalState();
}
Program: 57439
Project: 57439
Buggy source:
@Test public void testRandomPermutation(){
  for (int i=0; i < 10; i++) {
    @SuppressWarnings("String_Node_Str") DummyRandomKey drk=new DummyRandomKey(RandomKey.randomPermutation(20));
  }
}

Fixed version (ground truth):
@Test public void testRandomPermutation(){
  for (int i=0; i < 10; i++) {
    DummyRandomKey drk=new DummyRandomKey(RandomKey.randomPermutation(20));
    assertNotNull(drk);
  }
}
Program: 57440
Project: 57440
Buggy source:
/** 
 * test trace 
 */
public void testTrace(){
  BigMatrix m=new BigMatrixImpl(id);
  assertEquals("String_Node_Str",3d,m.getTrace().doubleValue(),entryTolerance);
  m=new BigMatrixImpl(testData2);
  try {
    m.getTrace().doubleValue();
    fail("String_Node_Str");
  }
 catch (  NonSquareMatrixException ex) {
  }
}

Fixed version (ground truth):
/** 
 * test trace 
 */
public void testTrace(){
  BigMatrix m=new BigMatrixImpl(id);
  assertEquals("String_Node_Str",3d,m.getTrace().doubleValue(),entryTolerance);
  m=new BigMatrixImpl(testData2);
  try {
    double t=m.getTrace().doubleValue();
    fail("String_Node_Str" + t);
  }
 catch (  NonSquareMatrixException ex) {
  }
}
Program: 57441
Project: 57441
Buggy source:
/** 
 * test determinant 
 */
public void testDeterminant(){
  BigMatrix m=new BigMatrixImpl(bigSingular);
  assertEquals("String_Node_Str",0,m.getDeterminant().doubleValue(),0);
  m=new BigMatrixImpl(detData);
  assertEquals("String_Node_Str",-3d,m.getDeterminant().doubleValue(),normTolerance);
  m=new BigMatrixImpl(detData2);
  assertEquals("String_Node_Str",-2d,m.getDeterminant().doubleValue(),normTolerance);
  m=new BigMatrixImpl(testData);
  assertEquals("String_Node_Str",-1d,m.getDeterminant().doubleValue(),normTolerance);
  try {
    new BigMatrixImpl(testData2).getDeterminant().doubleValue();
    fail("String_Node_Str");
  }
 catch (  InvalidMatrixException ex) {
  }
}

Fixed version (ground truth):
/** 
 * test determinant 
 */
public void testDeterminant(){
  BigMatrix m=new BigMatrixImpl(bigSingular);
  assertEquals("String_Node_Str",0,m.getDeterminant().doubleValue(),0);
  m=new BigMatrixImpl(detData);
  assertEquals("String_Node_Str",-3d,m.getDeterminant().doubleValue(),normTolerance);
  m=new BigMatrixImpl(detData2);
  assertEquals("String_Node_Str",-2d,m.getDeterminant().doubleValue(),normTolerance);
  m=new BigMatrixImpl(testData);
  assertEquals("String_Node_Str",-1d,m.getDeterminant().doubleValue(),normTolerance);
  try {
    double d=new BigMatrixImpl(testData2).getDeterminant().doubleValue();
    fail("String_Node_Str" + d);
  }
 catch (  InvalidMatrixException ex) {
  }
}
Program: 57443
Project: 57443
Buggy source:
/** 
 * {@inheritDoc} 
 */
public abstract void readExternal(ObjectInput in) throws IOException ;

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public abstract void readExternal(ObjectInput in) throws IOException, ClassNotFoundException ;
Program: 57444
Project: 57444
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public void writeExternal(final ObjectOutput out) throws IOException {
  writeBaseExternal(out);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public void writeExternal(final ObjectOutput out) throws IOException {
  writeBaseExternal(out);
  out.writeDouble(scalingH);
  out.writeDouble(referenceTime);
  final int n=(currentState == null) ? -1 : currentState.length;
  if (scaled == null) {
    out.writeBoolean(false);
  }
 else {
    out.writeBoolean(true);
    for (int j=0; j < n; ++j) {
      out.writeDouble(scaled[j]);
    }
  }
  if (nordsieck == null) {
    out.writeBoolean(false);
  }
 else {
    out.writeBoolean(true);
    out.writeObject(nordsieck);
  }
}
Program: 57445
Project: 57445
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public void readExternal(final ObjectInput in) throws IOException {
  final double t=readBaseExternal(in);
  if ((scaled != null) && (nordsieck != null)) {
    setInterpolatedTime(t);
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
  final double t=readBaseExternal(in);
  scalingH=in.readDouble();
  referenceTime=in.readDouble();
  final int n=(currentState == null) ? -1 : currentState.length;
  final boolean hasScaled=in.readBoolean();
  if (hasScaled) {
    scaled=new double[n];
    for (int j=0; j < n; ++j) {
      scaled[j]=in.readDouble();
    }
  }
 else {
    scaled=null;
  }
  final boolean hasNordsieck=in.readBoolean();
  if (hasNordsieck) {
    nordsieck=(Array2DRowRealMatrix)in.readObject();
  }
 else {
    nordsieck=null;
  }
  if (hasScaled && hasNordsieck) {
    setInterpolatedTime(t);
  }
}
Program: 57446
Project: 57446
Buggy source:
@Test public void serialization() throws DerivativeException, IntegratorException, IOException, ClassNotFoundException {
  TestProblem1 pb=new TestProblem1();
  AdamsBashforthIntegrator integ=new AdamsBashforthIntegrator(4,0.0,1.0,1.0e-10,1.0e-10);
  integ.addStepHandler(new ContinuousOutputModel());
  integ.integrate(pb,pb.getInitialTime(),pb.getInitialState(),pb.getFinalTime(),new double[pb.getDimension()]);
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  ObjectOutputStream oos=new ObjectOutputStream(bos);
  for (  StepHandler handler : integ.getStepHandlers()) {
    oos.writeObject(handler);
  }
  assertTrue(bos.size() > 16000);
  assertTrue(bos.size() < 17000);
  ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray());
  ObjectInputStream ois=new ObjectInputStream(bis);
  ContinuousOutputModel cm=(ContinuousOutputModel)ois.readObject();
  Random random=new Random(347588535632l);
  double maxError=0.0;
  for (int i=0; i < 1000; ++i) {
    double r=random.nextDouble();
    double time=r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
    cm.setInterpolatedTime(time);
    double[] interpolatedY=cm.getInterpolatedState();
    double[] theoreticalY=pb.computeTheoreticalState(time);
    double dx=interpolatedY[0] - theoreticalY[0];
    double dy=interpolatedY[1] - theoreticalY[1];
    double error=dx * dx + dy * dy;
    if (error > maxError) {
      maxError=error;
    }
  }
  assertTrue(maxError < 1.0e-6);
}

Fixed version (ground truth):
@Test public void serialization() throws DerivativeException, IntegratorException, IOException, ClassNotFoundException {
  TestProblem1 pb=new TestProblem1();
  AdamsBashforthIntegrator integ=new AdamsBashforthIntegrator(4,0.0,1.0,1.0e-10,1.0e-10);
  integ.addStepHandler(new ContinuousOutputModel());
  integ.integrate(pb,pb.getInitialTime(),pb.getInitialState(),pb.getFinalTime(),new double[pb.getDimension()]);
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  ObjectOutputStream oos=new ObjectOutputStream(bos);
  for (  StepHandler handler : integ.getStepHandlers()) {
    oos.writeObject(handler);
  }
  assertTrue(bos.size() > 20000);
  assertTrue(bos.size() < 25000);
  ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray());
  ObjectInputStream ois=new ObjectInputStream(bis);
  ContinuousOutputModel cm=(ContinuousOutputModel)ois.readObject();
  Random random=new Random(347588535632l);
  double maxError=0.0;
  for (int i=0; i < 1000; ++i) {
    double r=random.nextDouble();
    double time=r * pb.getInitialTime() + (1.0 - r) * pb.getFinalTime();
    cm.setInterpolatedTime(time);
    double[] interpolatedY=cm.getInterpolatedState();
    double[] theoreticalY=pb.computeTheoreticalState(time);
    double dx=interpolatedY[0] - theoreticalY[0];
    double dy=interpolatedY[1] - theoreticalY[1];
    double error=dx * dx + dy * dy;
    if (error > maxError) {
      maxError=error;
    }
  }
  assertTrue(maxError < 1.0e-6);
}
Program: 57447
Project: 57447
Buggy source:
protected AbstractIntegrator(){
  this(null);
}

Fixed version (ground truth):
/** 
 * Build an instance with a null name.
 */
protected AbstractIntegrator(){
  this(null);
}
Program: 57448
Project: 57448
Buggy source:
/** 
 * Compute the objective function value.
 * @param point point at which the objective function must be evaluated
 * @return objective function value at specified point
 * @exception FunctionEvaluationException if the function cannot be evaluatedor the maximal number of iterations is exceeded
 */
protected double computeObjectiveValue(final UnivariateRealFunction f,final double point) throws FunctionEvaluationException {
  if (++evaluations > maxEvaluations) {
    throw new FunctionEvaluationException(new MaxEvaluationsExceededException(maxEvaluations),point);
  }
  return f.value(point);
}

Fixed version (ground truth):
/** 
 * Compute the objective function value.
 * @param f objective function
 * @param point point at which the objective function must be evaluated
 * @return objective function value at specified point
 * @exception FunctionEvaluationException if the function cannot be evaluatedor the maximal number of iterations is exceeded
 */
protected double computeObjectiveValue(final UnivariateRealFunction f,final double point) throws FunctionEvaluationException {
  if (++evaluations > maxEvaluations) {
    throw new FunctionEvaluationException(new MaxEvaluationsExceededException(maxEvaluations),point);
  }
  return f.value(point);
}
Program: 57449
Project: 57449
Buggy source:
/** 
 * Build an Adams-Bashforth with the given order and step size.
 * @param nSteps number of steps of the method excluding the one being computed
 * @param minStep minimal step (must be positive even for backwardintegration), the last step can be smaller than this
 * @param maxStep maximal step (must be positive even for backwardintegration)
 * @param vecAbsoluteTolerance allowed absolute error
 * @param vecRelativeTolerance allowed relative error
 * @exception IllegalArgumentException if order is 1 or less
 */
public AdamsBashforthIntegrator(final int nSteps,final double minStep,final double maxStep,final double[] vecAbsoluteTolerance,final double[] vecRelativeTolerance) throws IllegalArgumentException {
  super("String_Node_Str",nSteps,nSteps + 1,minStep,maxStep,vecAbsoluteTolerance,vecRelativeTolerance);
}

Fixed version (ground truth):
/** 
 * Build an Adams-Bashforth with the given order and step size.
 * @param nSteps number of steps of the method excluding the one being computed
 * @param minStep minimal step (must be positive even for backwardintegration), the last step can be smaller than this
 * @param maxStep maximal step (must be positive even for backwardintegration)
 * @param vecAbsoluteTolerance allowed absolute error
 * @param vecRelativeTolerance allowed relative error
 * @exception IllegalArgumentException if order is 1 or less
 */
public AdamsBashforthIntegrator(final int nSteps,final double minStep,final double maxStep,final double[] vecAbsoluteTolerance,final double[] vecRelativeTolerance) throws IllegalArgumentException {
  super("String_Node_Str",nSteps,nSteps,minStep,maxStep,vecAbsoluteTolerance,vecRelativeTolerance);
}
Program: 57450
Project: 57450
Buggy source:
@Test public void testIncreasingTolerance() throws DerivativeException, IntegratorException {
  int previousCalls=Integer.MAX_VALUE;
  for (int i=-12; i < -2; ++i) {
    TestProblem1 pb=new TestProblem1();
    double minStep=0;
    double maxStep=pb.getFinalTime() - pb.getInitialTime();
    double scalAbsoluteTolerance=Math.pow(10.0,i);
    double scalRelativeTolerance=0.01 * scalAbsoluteTolerance;
    FirstOrderIntegrator integ=new AdamsBashforthIntegrator(4,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()]);
    assertTrue(handler.getMaximalValueError() > (28.0 * scalAbsoluteTolerance));
    assertTrue(handler.getMaximalValueError() < (42.0 * scalAbsoluteTolerance));
    assertEquals(0,handler.getMaximalTimeError(),1.0e-16);
    int calls=pb.getCalls();
    assertEquals(integ.getEvaluations(),calls);
    assertTrue(calls <= previousCalls);
    previousCalls=calls;
  }
}

Fixed version (ground truth):
@Test public void testIncreasingTolerance() throws DerivativeException, IntegratorException {
  int previousCalls=Integer.MAX_VALUE;
  for (int i=-12; i < -2; ++i) {
    TestProblem1 pb=new TestProblem1();
    double minStep=0;
    double maxStep=pb.getFinalTime() - pb.getInitialTime();
    double scalAbsoluteTolerance=Math.pow(10.0,i);
    double scalRelativeTolerance=0.01 * scalAbsoluteTolerance;
    FirstOrderIntegrator integ=new AdamsBashforthIntegrator(4,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()]);
    assertTrue(handler.getMaximalValueError() > (33.0 * scalAbsoluteTolerance));
    assertTrue(handler.getMaximalValueError() < (45.0 * scalAbsoluteTolerance));
    assertEquals(0,handler.getMaximalTimeError(),1.0e-16);
    int calls=pb.getCalls();
    assertEquals(integ.getEvaluations(),calls);
    assertTrue(calls <= previousCalls);
    previousCalls=calls;
  }
}
Program: 57452
Project: 57452
Buggy source:
/** 
 * @param crossoverPolicy The {@link CrossoverPolicy}
 * @param crossoverRate The crossover rate as a percentage (0-1 inclusive)
 * @param mutationPolicy The {@link MutationPolicy}
 * @param mutationRate The mutation rate as a percentage (0-1 inclusive)
 * @param selectionPolicy The {@link selectionPolicy}
 */
public GeneticAlgorithm(CrossoverPolicy crossoverPolicy,double crossoverRate,MutationPolicy mutationPolicy,double mutationRate,SelectionPolicy selectionPolicy){
  if (crossoverRate < 0 || crossoverRate > 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (mutationRate < 0 || mutationRate > 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.crossoverPolicy=crossoverPolicy;
  this.crossoverRate=crossoverRate;
  this.mutationPolicy=mutationPolicy;
  this.mutationRate=mutationRate;
  this.selectionPolicy=selectionPolicy;
}

Fixed version (ground truth):
/** 
 * @param crossoverPolicy The {@link CrossoverPolicy}
 * @param crossoverRate The crossover rate as a percentage (0-1 inclusive)
 * @param mutationPolicy The {@link MutationPolicy}
 * @param mutationRate The mutation rate as a percentage (0-1 inclusive)
 * @param selectionPolicy The {@link SelectionPolicy}
 */
public GeneticAlgorithm(CrossoverPolicy crossoverPolicy,double crossoverRate,MutationPolicy mutationPolicy,double mutationRate,SelectionPolicy selectionPolicy){
  if (crossoverRate < 0 || crossoverRate > 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (mutationRate < 0 || mutationRate > 1) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.crossoverPolicy=crossoverPolicy;
  this.crossoverRate=crossoverRate;
  this.mutationPolicy=mutationPolicy;
  this.mutationRate=mutationRate;
  this.selectionPolicy=selectionPolicy;
}
Program: 57453
Project: 57453
Buggy source:
/** 
 * {@inheritDoc} 
 */
public int eventOccurred(double t,double[] y,boolean increasing) throws EventException {
  final int action=handler.eventOccurred(t,y,increasing);
  if ((action == RESET_DERIVATIVES) || (action == RESET_STATE)) {
    resetTime=t;
    return STOP;
  }
  return action;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public int eventOccurred(double t,double[] y,boolean increasing) throws EventException {
  final int action=handler.eventOccurred(t,y,increasing);
  if (Math.abs(t - rangeStart) < 1.0e-10 * rangeSize) {
    return action;
  }
  if ((action == RESET_DERIVATIVES) || (action == RESET_STATE)) {
    resetTime=t;
    return STOP;
  }
  return action;
}
Program: 57455
Project: 57455
Buggy source:
/** 
 * Get the current solution. <p>  {@link #solve} should be called first for this to be the optimal solution.</p>
 * @return current solution
 */
protected RealPointValuePair getSolution(){
  double[] coefficients=new double[getOriginalNumDecisionVariables()];
  double mostNegative=getDecisionVariableValue(getOriginalNumDecisionVariables());
  for (int i=0; i < coefficients.length; i++) {
    coefficients[i]=getDecisionVariableValue(i) - (restrictToNonNegative ? 0 : mostNegative);
  }
  return new RealPointValuePair(coefficients,f.getValue(coefficients));
}

Fixed version (ground truth):
/** 
 * Get the current solution. <p>  {@link #solve} should be called first for this to be the optimal solution.</p>
 * @return current solution
 */
protected RealPointValuePair getSolution(){
  double[] coefficients=new double[getOriginalNumDecisionVariables()];
  Integer basicRow=getBasicRow(getNumObjectiveFunctions() + getOriginalNumDecisionVariables());
  double mostNegative=basicRow == null ? 0 : getEntry(basicRow,getRhsOffset());
  Set<Integer> basicRows=new HashSet<Integer>();
  for (int i=0; i < coefficients.length; i++) {
    basicRow=getBasicRow(getNumObjectiveFunctions() + i);
    if (basicRows.contains(basicRow)) {
      coefficients[i]=0;
    }
 else {
      basicRows.add(basicRow);
      coefficients[i]=(basicRow == null ? 0 : getEntry(basicRow,getRhsOffset())) - (restrictToNonNegative ? 0 : mostNegative);
    }
  }
  return new RealPointValuePair(coefficients,f.getValue(coefficients));
}
Program: 57456
Project: 57456
Buggy source:
/** 
 * Set the differential equations.
 * @see #computeDerivatives(double,double[],double[])
 */
protected void setEquations(final FirstOrderDifferentialEquations equations){
  this.equations=equations;
}

Fixed version (ground truth):
/** 
 * Set the differential equations.
 * @param equations differential equations to integrate
 * @see #computeDerivatives(double,double[],double[])
 */
protected void setEquations(final FirstOrderDifferentialEquations equations){
  this.equations=equations;
}
Program: 57458
Project: 57458
Buggy source:
/** 
 * Test for the equality of two real vectors. <p> If all coordinates of two real vectors are exactly the same, and none are <code>Double.NaN</code>, the two real vectors are considered to be equal. </p> <p> <code>NaN</code> coordinates are considered to affect globally the vector and be equals to each other - i.e, if either (or all) coordinates of the real vector are equal to <code>Double.NaN</code>, the real vector is equal to a vector with all <code>Double.NaN</code> coordinates. </p>
 * @param other Object to test for equality to this
 * @return true if two 3D vector objects are equal, false ifobject is null, not an instance of Vector3D, or not equal to this Vector3D instance
 */
@Override public boolean equals(Object other){
  if (this == other) {
    return true;
  }
  if (other == null) {
    return false;
  }
  try {
    RealVector rhs=(RealVector)other;
    if (data.length != rhs.getDimension()) {
      return false;
    }
    if (rhs.isNaN()) {
      return this.isNaN();
    }
    for (int i=0; i < data.length; ++i) {
      if (data[i] != rhs.getEntry(i)) {
        return false;
      }
    }
    return true;
  }
 catch (  ClassCastException ex) {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Test for the equality of two real vectors. <p> If all coordinates of two real vectors are exactly the same, and none are <code>Double.NaN</code>, the two real vectors are considered to be equal. </p> <p> <code>NaN</code> coordinates are considered to affect globally the vector and be equals to each other - i.e, if either (or all) coordinates of the real vector are equal to <code>Double.NaN</code>, the real vector is equal to a vector with all <code>Double.NaN</code> coordinates. </p>
 * @param other Object to test for equality to this
 * @return true if two vector objects are equal, false ifobject is null, not an instance of RealVector, or not equal to this RealVector instance
 */
@Override public boolean equals(Object other){
  if (this == other) {
    return true;
  }
  if (other == null) {
    return false;
  }
  try {
    RealVector rhs=(RealVector)other;
    if (data.length != rhs.getDimension()) {
      return false;
    }
    if (rhs.isNaN()) {
      return this.isNaN();
    }
    for (int i=0; i < data.length; ++i) {
      if (data[i] != rhs.getEntry(i)) {
        return false;
      }
    }
    return true;
  }
 catch (  ClassCastException ex) {
    return false;
  }
}
Program: 57459
Project: 57459
Buggy source:
/** 
 * Compute the gamma star coefficients.
 * @param order order of the integration method
 * @return gamma star coefficients array
 */
static Fraction[] computeGammaStarArray(final int order){
  Fraction[] gammaStarArray=new Fraction[order + 1];
  gammaStarArray[0]=Fraction.ONE;
  for (int i=1; i <= order; ++i) {
    Fraction gammaStar=Fraction.ZERO;
    for (int j=1; j <= i; ++j) {
      gammaStar=gammaStar.subtract(gammaStarArray[i - j].multiply(new Fraction(1,j + 1)));
    }
    gammaStarArray[i]=gammaStar;
  }
  return gammaStarArray;
}

Fixed version (ground truth):
/** 
 * Compute the gamma star coefficients.
 * @param order order of the integration method
 * @return gamma star coefficients array
 */
public static Fraction[] computeGammaStarArray(final int order){
  Fraction[] gammaStarArray=new Fraction[order + 1];
  gammaStarArray[0]=Fraction.ONE;
  for (int i=1; i <= order; ++i) {
    Fraction gammaStar=Fraction.ZERO;
    for (int j=1; j <= i; ++j) {
      gammaStar=gammaStar.subtract(gammaStarArray[i - j].multiply(new Fraction(1,j + 1)));
    }
    gammaStarArray[i]=gammaStar;
  }
  return gammaStarArray;
}
Program: 57460
Project: 57460
Buggy source:
/** 
 * Build an Adams-Moulton integrator with the given order and step size.
 * @param order order of the method (must be strictly positive)
 * @param step integration step size
 */
public AdamsMoultonIntegrator(final int order,final double step){
  super(METHOD_NAME,order + 1,new AdamsMoultonStepInterpolator());
  int[][] bdArray=AdamsBashforthIntegrator.computeBackwardDifferencesArray(order + 1);
  Fraction[] gamma=AdamsBashforthIntegrator.computeGammaArray(order);
  predictorCoeffs=new double[order];
  for (int i=0; i < order; ++i) {
    Fraction fPredictor=Fraction.ZERO;
    for (int j=i; j < order; ++j) {
      Fraction f=new Fraction(bdArray[j][i],1);
      fPredictor=fPredictor.add(gamma[j].multiply(f));
    }
    predictorCoeffs[i]=fPredictor.doubleValue();
  }
  Fraction[] gammaStar=computeGammaStarArray(order);
  correctorCoeffs=new double[order + 1];
  for (int i=0; i <= order; ++i) {
    Fraction fCorrector=Fraction.ZERO;
    for (int j=i; j <= order; ++j) {
      Fraction f=new Fraction(bdArray[j][i],1);
      fCorrector=fCorrector.add(gammaStar[j].multiply(f));
    }
    correctorCoeffs[i]=fCorrector.doubleValue();
  }
  this.step=Math.abs(step);
}

Fixed version (ground truth):
/** 
 * Build an Adams-Moulton integrator with the given order and step size.
 * @param order order of the method (must be strictly positive)
 * @param step integration step size
 */
public AdamsMoultonIntegrator(final int order,final double step){
  super(METHOD_NAME,order + 1,new AdamsMoultonStepInterpolator());
  int[][] bdArray=AdamsBashforthIntegrator.computeBackwardDifferencesArray(order);
  Fraction[] gamma=AdamsBashforthIntegrator.computeGammaArray(order);
  predictorCoeffs=new double[order];
  for (int i=0; i < order; ++i) {
    Fraction fPredictor=Fraction.ZERO;
    for (int j=i; j < order; ++j) {
      Fraction f=new Fraction(bdArray[j][i],1);
      fPredictor=fPredictor.add(gamma[j].multiply(f));
    }
    predictorCoeffs[i]=fPredictor.doubleValue();
  }
  Fraction[] gammaStar=computeGammaStarArray(order);
  correctorCoeffs=new double[order];
  for (int i=0; i < order; ++i) {
    Fraction fCorrector=Fraction.ZERO;
    for (int j=i; j < order; ++j) {
      Fraction f=new Fraction(bdArray[j][i],1);
      fCorrector=fCorrector.add(gammaStar[j].multiply(f));
    }
    correctorCoeffs[i]=fCorrector.doubleValue();
  }
  this.step=Math.abs(step);
}
Program: 57462
Project: 57462
Buggy source:
public void testSmallStep() throws DerivativeException, IntegratorException {
  TestProblem1 pb=new TestProblem1();
  double step=(pb.getFinalTime() - pb.getInitialTime()) * 0.001;
  FirstOrderIntegrator integ=new AdamsMoultonIntegrator(3,step);
  TestProblemHandler handler=new TestProblemHandler(pb,integ);
  integ.addStepHandler(handler);
  integ.integrate(pb,pb.getInitialTime(),pb.getInitialState(),pb.getFinalTime(),new double[pb.getDimension()]);
  assertTrue(handler.getLastError() < 7.0e-12);
  assertTrue(handler.getMaximalValueError() < 4.0e-11);
  assertEquals(0,handler.getMaximalTimeError(),1.0e-14);
  assertEquals("String_Node_Str",integ.getName());
}

Fixed version (ground truth):
public void testSmallStep() throws DerivativeException, IntegratorException {
  TestProblem1 pb=new TestProblem1();
  double step=(pb.getFinalTime() - pb.getInitialTime()) * 0.001;
  FirstOrderIntegrator integ=new AdamsMoultonIntegrator(3,step);
  TestProblemHandler handler=new TestProblemHandler(pb,integ);
  integ.addStepHandler(handler);
  integ.integrate(pb,pb.getInitialTime(),pb.getInitialState(),pb.getFinalTime(),new double[pb.getDimension()]);
  assertTrue(handler.getLastError() < 3.0e-10);
  assertTrue(handler.getMaximalValueError() < 2.0e-9);
  assertEquals(0,handler.getMaximalTimeError(),1.0e-15);
  assertEquals("String_Node_Str",integ.getName());
}
Program: 57463
Project: 57463
Buggy source:
/** 
 * {@inheritDoc} 
 */
public boolean isInfinite(){
  Iterator iter=entries.iterator();
  while (iter.hasNext()) {
    iter.advance();
    if (Double.isInfinite(iter.value())) {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public boolean isInfinite(){
  boolean infiniteFound=false;
  boolean nanFound=false;
  Iterator iter=entries.iterator();
  while (iter.hasNext()) {
    iter.advance();
    final double value=iter.value();
    if (Double.isNaN(value)) {
      nanFound=true;
    }
    if (Double.isInfinite(value)) {
      infiniteFound=true;
    }
  }
  return infiniteFound && (!nanFound);
}
Program: 57464
Project: 57464
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public int hashCode(){
  final int prime=31;
  int result=1;
  long temp;
  temp=Double.doubleToLongBits(epsilon);
  result=prime * result + (int)(temp ^ (temp >>> 32));
  result=prime * result + virtualSize;
  return result;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public int hashCode(){
  final int prime=31;
  int result=1;
  long temp;
  temp=Double.doubleToLongBits(epsilon);
  result=prime * result + (int)(temp ^ (temp >>> 32));
  result=prime * result + virtualSize;
  Iterator iter=entries.iterator();
  while (iter.hasNext()) {
    iter.advance();
    temp=Double.doubleToLongBits(iter.value());
    result=prime * result + (int)(temp ^ (temp >>> 32));
  }
  return result;
}
Program: 57465
Project: 57465
Buggy source:
public void testPredicates(){
  SparseRealVector v=new SparseRealVector(new double[]{0,1,2});
  assertFalse(v.isNaN());
  v.setEntry(1,Double.NaN);
  assertTrue(v.isNaN());
  assertFalse(v.isInfinite());
  v.setEntry(0,Double.POSITIVE_INFINITY);
  assertFalse(v.isInfinite());
  v.setEntry(1,1);
  assertTrue(v.isInfinite());
  v.setEntry(0,0);
  assertEquals(v,new SparseRealVector(new double[]{0,1,2}));
  assertNotSame(v,new SparseRealVector(new double[]{0,1,2 + Math.ulp(2)}));
  assertNotSame(v,new SparseRealVector(new double[]{0,1,2,3}));
  assertEquals(new SparseRealVector(new double[]{Double.NaN,1,2}).hashCode(),new SparseRealVector(new double[]{0,Double.NaN,2}).hashCode());
  assertTrue(new SparseRealVector(new double[]{Double.NaN,1,2}).hashCode() != new SparseRealVector(new double[]{0,1,2}).hashCode());
}

Fixed version (ground truth):
public void testPredicates(){
  SparseRealVector v=new SparseRealVector(new double[]{0,1,2});
  assertFalse(v.isNaN());
  v.setEntry(1,Double.NaN);
  assertTrue(v.isNaN());
  assertFalse(v.isInfinite());
  v.setEntry(0,Double.POSITIVE_INFINITY);
  assertFalse(v.isInfinite());
  v.setEntry(1,1);
  assertTrue(v.isInfinite());
  v.setEntry(0,0);
  assertEquals(v,new SparseRealVector(new double[]{0,1,2}));
  assertNotSame(v,new SparseRealVector(new double[]{0,1,2 + Math.ulp(2)}));
  assertNotSame(v,new SparseRealVector(new double[]{0,1,2,3}));
  assertTrue(new SparseRealVector(new double[]{Double.NaN,1,2}).hashCode() != new SparseRealVector(new double[]{0,Double.NaN,2}).hashCode());
  assertTrue(new SparseRealVector(new double[]{Double.NaN,1,2}).hashCode() != new SparseRealVector(new double[]{0,1,2}).hashCode());
}
Program: 57466
Project: 57466
Buggy source:
/** 
 * Translate a string to a given locale.
 * @param s string to translate
 * @param locale locale into which to translate the string
 * @return translated string or original stringfor unsupported locales or unknown strings
 */
private static String translate(String s,Locale locale){
  try {
    if ((cachedResources == null) || (!cachedResources.getLocale().equals(locale))) {
      cachedResources=ResourceBundle.getBundle("String_Node_Str",locale);
    }
    if (cachedResources.getLocale().getLanguage().equals(locale.getLanguage())) {
      return cachedResources.getString(s);
    }
  }
 catch (  MissingResourceException mre) {
  }
  return s;
}

Fixed version (ground truth):
/** 
 * Translate a string to a given locale.
 * @param s string to translate
 * @param locale locale into which to translate the string
 * @return translated string or original stringfor unsupported locales or unknown strings
 */
private static String translate(String s,Locale locale){
  try {
    ResourceBundle bundle=ResourceBundle.getBundle("String_Node_Str",locale);
    if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
      return bundle.getString(s);
    }
  }
 catch (  MissingResourceException mre) {
  }
  return s;
}
Program: 57467
Project: 57467
Buggy source:
/** 
 * Translate a string to a given locale.
 * @param s string to translate
 * @param locale locale into which to translate the string
 * @return translated string or original stringfor unsupported locales or unknown strings
 */
private static String translate(final String s,final Locale locale){
  try {
    if ((cachedResources == null) || (!cachedResources.getLocale().equals(locale))) {
      cachedResources=ResourceBundle.getBundle("String_Node_Str",locale);
    }
    if (cachedResources.getLocale().getLanguage().equals(locale.getLanguage())) {
      return cachedResources.getString(s);
    }
  }
 catch (  MissingResourceException mre) {
  }
  return s;
}

Fixed version (ground truth):
/** 
 * Translate a string to a given locale.
 * @param s string to translate
 * @param locale locale into which to translate the string
 * @return translated string or original stringfor unsupported locales or unknown strings
 */
private static String translate(final String s,final Locale locale){
  try {
    ResourceBundle bundle=ResourceBundle.getBundle("String_Node_Str",locale);
    if (bundle.getLocale().getLanguage().equals(locale.getLanguage())) {
      return bundle.getString(s);
    }
  }
 catch (  MissingResourceException mre) {
  }
  return s;
}
Program: 57468
Project: 57468
Buggy source:
/** 
 * Convenience method to find a zero of a univariate real function.  A default solver is used. 
 * @param f the function
 * @param x0 the lower bound for the interval
 * @param x1 the upper bound for the interval
 * @param absoluteAccuracy the accuracy to be used by the solver
 * @return a value where the function is zero
 * @throws ConvergenceException if the iteration count is exceeded
 * @throws FunctionEvaluationException if an error occurs evaluating thefunction
 * @throws IllegalArgumentException if f is null, the endpoints do not specify a valid interval, or the absoluteAccuracy is not valid for the default solver
 */
public static double solve(UnivariateRealFunction f,double x0,double x1,double absoluteAccuracy) throws ConvergenceException, FunctionEvaluationException {
  setup(f);
  UnivariateRealSolver solver=factory.newDefaultSolver();
  solver.setAbsoluteAccuracy(absoluteAccuracy);
  return solver.solve(f,x0,x1);
}

Fixed version (ground truth):
/** 
 * Convenience method to find a zero of a univariate real function.  A default solver is used. 
 * @param f the function
 * @param x0 the lower bound for the interval
 * @param x1 the upper bound for the interval
 * @param absoluteAccuracy the accuracy to be used by the solver
 * @return a value where the function is zero
 * @throws ConvergenceException if the iteration count is exceeded
 * @throws FunctionEvaluationException if an error occurs evaluating thefunction
 * @throws IllegalArgumentException if f is null, the endpoints do not specify a valid interval, or the absoluteAccuracy is not valid for the default solver
 */
public static double solve(UnivariateRealFunction f,double x0,double x1,double absoluteAccuracy) throws ConvergenceException, FunctionEvaluationException {
  setup(f);
  UnivariateRealSolver solver=LazyHolder.FACTORY.newDefaultSolver();
  solver.setAbsoluteAccuracy(absoluteAccuracy);
  return solver.solve(f,x0,x1);
}
Program: 57469
Project: 57469
Buggy source:
/** 
 * Checks to see if f is null, throwing IllegalArgumentException if so. Also initializes factory if factory is null.
 * @param f  input function
 * @throws IllegalArgumentException if f is null
 */
private static void setup(UnivariateRealFunction f){
  if (f == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (factory == null) {
    factory=UnivariateRealSolverFactory.newInstance();
  }
}

Fixed version (ground truth):
/** 
 * Checks to see if f is null, throwing IllegalArgumentException if so.
 * @param f  input function
 * @throws IllegalArgumentException if f is null
 */
private static void setup(UnivariateRealFunction f){
  if (f == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
}
Program: 57470
Project: 57470
Buggy source:
/** 
 * Compares this object to another based on size.
 * @param object the object to compare to
 * @return -1 if this is less than <tt>object</tt>, +1 if this is greaterthan <tt>object</tt>, 0 if they are equal.
 */
public int compareTo(Fraction object){
  int ret=0;
  if (this != object) {
    double first=doubleValue();
    double second=object.doubleValue();
    if (first < second) {
      ret=-1;
    }
 else     if (first > second) {
      ret=1;
    }
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * Compares this object to another based on size.
 * @param object the object to compare to
 * @return -1 if this is less than <tt>object</tt>, +1 if this is greaterthan <tt>object</tt>, 0 if they are equal.
 */
public int compareTo(Fraction object){
  long nOd=((long)numerator) * object.denominator;
  long dOn=((long)denominator) * object.numerator;
  return (nOd < dOn) ? -1 : ((nOd > dOn) ? +1 : 0);
}
Program: 57471
Project: 57471
Buggy source:
/** 
 * Get the value of the given decision variable.  This is not the actual value as it is guaranteed to be >= 0 and thus must be corrected before being returned to the user.
 * @param decisionVariable The index of the decision variable
 * @return The value of the given decision variable.
 */
protected double getDecisionVariableValue(final int decisionVariable){
  Integer basicRow=getBasicRow(getNumObjectiveFunctions() + decisionVariable);
  return basicRow == null ? 0 : getEntry(basicRow,getRhsOffset());
}

Fixed version (ground truth):
/** 
 * Get the value of the given decision variable.  This is not the actual value as it is guaranteed to be >= 0 and thus must be corrected before being returned to the user.
 * @param decisionVariable The index of the decision variable
 * @return The value of the given decision variable.
 */
protected double getDecisionVariableValue(final int decisionVariable){
  int col=getNumObjectiveFunctions() + decisionVariable;
  Integer basicRow=getBasicRow(col);
  if (basicRow == null) {
    return 0;
  }
  for (int i=getNumObjectiveFunctions(); i < col; i++) {
    if (tableau.getEntry(basicRow,i) == 1) {
      return 0;
    }
  }
  return getEntry(basicRow,getRhsOffset());
}
Program: 57473
Project: 57473
Buggy source:
/** 
 * Set an entry of the tableau.
 * @param row row index
 * @param column column indexparam value for the entry
 */
protected final void setEntry(final int row,final int column,final double value){
  tableau.setEntry(row,column,value);
}

Fixed version (ground truth):
/** 
 * Set an entry of the tableau.
 * @param row row index
 * @param column column index
 * @param value for the entry
 */
protected final void setEntry(final int row,final int column,final double value){
  tableau.setEntry(row,column,value);
}
Program: 57474
Project: 57474
Buggy source:
public void testInterpolateLinearDegenerateTwoSegment() throws Exception {
  double x[]={0.0,0.5,1.0};
  double y[]={0.0,0.5,1.0};
  UnivariateRealInterpolator i=new SplineInterpolator();
  UnivariateRealFunction f=i.interpolate(x,y);
  verifyInterpolation(f,x,y);
  verifyConsistency((PolynomialSplineFunction)f,x);
  PolynomialFunction polynomials[]=((PolynomialSplineFunction)f).getPolynomials();
  double target[]={y[0],1d,0d,0d};
  TestUtils.assertEquals(polynomials[0].getCoefficients(),target,coefficientTolerance);
  target=new double[]{y[1],1d,0d,0d};
  TestUtils.assertEquals(polynomials[1].getCoefficients(),target,coefficientTolerance);
  assertEquals(0.0,f.value(0.0),interpolationTolerance);
  assertEquals(0.4,f.value(0.4),interpolationTolerance);
  assertEquals(1.0,f.value(1.0),interpolationTolerance);
}

Fixed version (ground truth):
public void testInterpolateLinearDegenerateTwoSegment() throws Exception {
  double x[]={0.0,0.5,1.0};
  double y[]={0.0,0.5,1.0};
  UnivariateRealInterpolator i=new SplineInterpolator();
  UnivariateRealFunction f=i.interpolate(x,y);
  verifyInterpolation(f,x,y);
  verifyConsistency((PolynomialSplineFunction)f,x);
  PolynomialFunction polynomials[]=((PolynomialSplineFunction)f).getPolynomials();
  double target[]={y[0],1d};
  TestUtils.assertEquals(polynomials[0].getCoefficients(),target,coefficientTolerance);
  target=new double[]{y[1],1d};
  TestUtils.assertEquals(polynomials[1].getCoefficients(),target,coefficientTolerance);
  assertEquals(0.0,f.value(0.0),interpolationTolerance);
  assertEquals(0.4,f.value(0.4),interpolationTolerance);
  assertEquals(1.0,f.value(1.0),interpolationTolerance);
}
Program: 57475
Project: 57475
Buggy source:
public void testInterpolateLinearDegenerateThreeSegment() throws Exception {
  double x[]={0.0,0.5,1.0,1.5};
  double y[]={0.0,0.5,1.0,1.5};
  UnivariateRealInterpolator i=new SplineInterpolator();
  UnivariateRealFunction f=i.interpolate(x,y);
  verifyInterpolation(f,x,y);
  PolynomialFunction polynomials[]=((PolynomialSplineFunction)f).getPolynomials();
  double target[]={y[0],1d,0d,0d};
  TestUtils.assertEquals(polynomials[0].getCoefficients(),target,coefficientTolerance);
  target=new double[]{y[1],1d,0d,0d};
  TestUtils.assertEquals(polynomials[1].getCoefficients(),target,coefficientTolerance);
  target=new double[]{y[2],1d,0d,0d};
  TestUtils.assertEquals(polynomials[2].getCoefficients(),target,coefficientTolerance);
  assertEquals(0,f.value(0),interpolationTolerance);
  assertEquals(1.4,f.value(1.4),interpolationTolerance);
  assertEquals(1.5,f.value(1.5),interpolationTolerance);
}

Fixed version (ground truth):
public void testInterpolateLinearDegenerateThreeSegment() throws Exception {
  double x[]={0.0,0.5,1.0,1.5};
  double y[]={0.0,0.5,1.0,1.5};
  UnivariateRealInterpolator i=new SplineInterpolator();
  UnivariateRealFunction f=i.interpolate(x,y);
  verifyInterpolation(f,x,y);
  PolynomialFunction polynomials[]=((PolynomialSplineFunction)f).getPolynomials();
  double target[]={y[0],1d};
  TestUtils.assertEquals(polynomials[0].getCoefficients(),target,coefficientTolerance);
  target=new double[]{y[1],1d};
  TestUtils.assertEquals(polynomials[1].getCoefficients(),target,coefficientTolerance);
  target=new double[]{y[2],1d};
  TestUtils.assertEquals(polynomials[2].getCoefficients(),target,coefficientTolerance);
  assertEquals(0,f.value(0),interpolationTolerance);
  assertEquals(1.4,f.value(1.4),interpolationTolerance);
  assertEquals(1.5,f.value(1.5),interpolationTolerance);
}