nus-yam/ex-repair huggingface dataset:
Program: 150853
Project: 150853
Buggy source:
/** 
 * Given a node and the corner to the next node down the line, add to the list every other node until it hits the end of the row.
 * @param n Initial node
 * @param corner Which corner points to the next node
 * @param sign Determines the direction it will traverse.  -1 or 1
 * @param skip true = start adding nodes at second, false = start first.
 * @param row List that the nodes are placed into
 */
static void addToRow(SquareNode n,int corner,int sign,boolean skip,List<SquareNode> row){
  SquareEdge e;
  while ((e=n.edges[corner]) != null) {
    if (e.a == n) {
      n=e.b;
      corner=e.sideB;
    }
 else {
      n=e.a;
      corner=e.sideA;
    }
    if (!skip) {
      if (n.graph != SquareNode.RESET_GRAPH)       throw new RuntimeException("String_Node_Str");
      n.graph=0;
      row.add(n);
    }
    skip=!skip;
    sign*=-1;
    corner=addOffset(corner,sign,4);
  }
}

Fixed version (ground truth):
/** 
 * Given a node and the corner to the next node down the line, add to the list every other node until it hits the end of the row.
 * @param n Initial node
 * @param corner Which corner points to the next node
 * @param sign Determines the direction it will traverse.  -1 or 1
 * @param skip true = start adding nodes at second, false = start first.
 * @param row List that the nodes are placed into
 */
boolean addToRow(SquareNode n,int corner,int sign,boolean skip,List<SquareNode> row){
  SquareEdge e;
  while ((e=n.edges[corner]) != null) {
    if (e.a == n) {
      n=e.b;
      corner=e.sideB;
    }
 else {
      n=e.a;
      corner=e.sideA;
    }
    if (!skip) {
      if (n.graph != SquareNode.RESET_GRAPH) {
        invalid=true;
        return false;
      }
      n.graph=0;
      row.add(n);
    }
    skip=!skip;
    sign*=-1;
    corner=addOffset(corner,sign,4);
  }
  return true;
}
Program: 150854
Project: 150854
Buggy source:
/** 
 * Adds the first row to the list of rows when the seed element has only one edge
 */
List<SquareNode> firstRow1(SquareNode seed){
  for (int i=0; i < 4; i++) {
    if (isOpenEdge(seed,i)) {
      List<SquareNode> list=new ArrayList<SquareNode>();
      seed.graph=0;
      int corner=seed.edges[i].destinationSide(seed);
      int l=addOffset(corner,-1,4);
      int u=addOffset(corner,1,4);
      SquareNode dst=seed.edges[i].destination(seed);
      if (dst.edges[u] != null) {
        list.add(seed);
        addToRow(seed,i,-1,true,list);
      }
 else       if (dst.edges[l] != null) {
        List<SquareNode> tmp=new ArrayList<SquareNode>();
        addToRow(seed,i,1,true,tmp);
        flipAdd(tmp,list);
        list.add(seed);
      }
 else {
        list.add(seed);
      }
      return list;
    }
  }
  throw new RuntimeException("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Adds the first row to the list of rows when the seed element has only one edge
 */
List<SquareNode> firstRow1(SquareNode seed){
  for (int i=0; i < 4; i++) {
    if (isOpenEdge(seed,i)) {
      List<SquareNode> list=new ArrayList<SquareNode>();
      seed.graph=0;
      int corner=seed.edges[i].destinationSide(seed);
      int l=addOffset(corner,-1,4);
      int u=addOffset(corner,1,4);
      SquareNode dst=seed.edges[i].destination(seed);
      if (dst.edges[u] != null) {
        list.add(seed);
        if (!addToRow(seed,i,-1,true,list))         return null;
      }
 else       if (dst.edges[l] != null) {
        List<SquareNode> tmp=new ArrayList<SquareNode>();
        if (!addToRow(seed,i,1,true,tmp))         return null;
        flipAdd(tmp,list);
        list.add(seed);
      }
 else {
        list.add(seed);
      }
      return list;
    }
  }
  throw new RuntimeException("String_Node_Str");
}
Program: 150855
Project: 150855
Buggy source:
/** 
 * Given a node, add all the squares in the row directly below it.  They will be ordered from "left" to "right".  The seed node can be anywhere in the row, e.g. middle, start, end.
 * @return true if a row was added to grid and false if not
 */
boolean addNextRow(SquareNode seed,List<List<SquareNode>> grid){
  List<SquareNode> row=new ArrayList<SquareNode>();
  List<SquareNode> tmp=new ArrayList<SquareNode>();
  int numConnections=numberOfOpenEdges(seed);
  if (numConnections == 0) {
    return false;
  }
 else   if (numConnections == 1) {
    for (int i=0; i < 4; i++) {
      SquareEdge edge=seed.edges[i];
      if (edge != null) {
        SquareNode dst=edge.destination(seed);
        if (dst.graph != SquareNode.RESET_GRAPH)         continue;
        int corner=edge.destinationSide(seed);
        int l=addOffset(corner,-1,4);
        int u=addOffset(corner,1,4);
        if (isClosedValidEdge(dst,l)) {
          addToRow(seed,i,1,false,tmp);
          flipAdd(tmp,row);
        }
 else         if (isClosedValidEdge(dst,u)) {
          addToRow(seed,i,-1,false,row);
        }
 else {
          dst.graph=0;
          row.add(dst);
        }
        break;
      }
    }
  }
 else   if (numConnections == 2) {
    int indexLower=lowerEdgeIndex(seed);
    int indexUpper=addOffset(indexLower,1,4);
    addToRow(seed,indexUpper,1,false,tmp);
    flipAdd(tmp,row);
    addToRow(seed,indexLower,-1,false,row);
  }
 else {
    return false;
  }
  grid.add(row);
  return true;
}

Fixed version (ground truth):
/** 
 * Given a node, add all the squares in the row directly below it.  They will be ordered from "left" to "right".  The seed node can be anywhere in the row, e.g. middle, start, end.
 * @return true if a row was added to grid and false if not
 */
boolean addNextRow(SquareNode seed,List<List<SquareNode>> grid){
  List<SquareNode> row=new ArrayList<SquareNode>();
  List<SquareNode> tmp=new ArrayList<SquareNode>();
  int numConnections=numberOfOpenEdges(seed);
  if (numConnections == 0) {
    return false;
  }
 else   if (numConnections == 1) {
    for (int i=0; i < 4; i++) {
      SquareEdge edge=seed.edges[i];
      if (edge != null) {
        SquareNode dst=edge.destination(seed);
        if (dst.graph != SquareNode.RESET_GRAPH)         continue;
        int corner=edge.destinationSide(seed);
        int l=addOffset(corner,-1,4);
        int u=addOffset(corner,1,4);
        if (isClosedValidEdge(dst,l)) {
          if (!addToRow(seed,i,1,false,tmp))           return false;
          flipAdd(tmp,row);
        }
 else         if (isClosedValidEdge(dst,u)) {
          if (!addToRow(seed,i,-1,false,row))           return false;
        }
 else {
          dst.graph=0;
          row.add(dst);
        }
        break;
      }
    }
  }
 else   if (numConnections == 2) {
    int indexLower=lowerEdgeIndex(seed);
    int indexUpper=addOffset(indexLower,1,4);
    if (!addToRow(seed,indexUpper,1,false,tmp))     return false;
    flipAdd(tmp,row);
    if (!addToRow(seed,indexLower,-1,false,row))     return false;
  }
 else {
    return false;
  }
  grid.add(row);
  return true;
}
Program: 150856
Project: 150856
Buggy source:
@Override public void process(T input){
  if (periodX <= 0 || periodY <= 0)   throw new IllegalArgumentException("String_Node_Str");
  alg.setImage(input);
  int x0=featureWidth / 2;
  int x1=input.getWidth() - featureWidth / 2;
  int y0=featureWidth / 2;
  int y1=input.getHeight() - featureWidth / 2;
  descriptions.reset();
  locations.reset();
  for (int y=y0; y < y1; y+=periodY) {
    for (int x=x0; x < x1; x+=periodX) {
      Desc d=descriptions.grow();
      if (!alg.process(x,y,0,scale,d)) {
        descriptions.removeTail();
      }
 else {
        locations.grow().set(x,y);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void process(T input){
  if (periodX <= 0 || periodY <= 0)   throw new IllegalArgumentException("String_Node_Str");
  alg.setImage(input);
  int x0=featureWidth / 2;
  int x1=input.getWidth() - featureWidth / 2;
  int y0=featureWidth / 2;
  int y1=input.getHeight() - featureWidth / 2;
  descriptions.reset();
  locations.reset();
  for (int y=y0; y < y1; y+=periodY) {
    for (int x=x0; x < x1; x+=periodX) {
      Desc d=descriptions.grow();
      if (!alg.process(x,y,0,radius,d)) {
        descriptions.removeTail();
      }
 else {
        locations.grow().set(x,y);
      }
    }
  }
}
Program: 150857
Project: 150857
Buggy source:
/** 
 * Configures dense description.
 * @param alg Sparse feature sampler.
 */
public GenericDenseDescribeImageDense(DescribeRegionPoint<T,Desc> alg){
  this.alg=alg;
}

Fixed version (ground truth):
/** 
 * Configures dense description.
 * @param alg Sparse feature sampler.
 */
public GenericDenseDescribeImageDense(DescribeRegionPoint<T,Desc> alg,double scaleToRadius){
  this.scaleToRadius=scaleToRadius;
  this.alg=alg;
}
Program: 150858
Project: 150858
Buggy source:
@Override public void configure(double scale,double periodX,double periodY){
  this.scale=scale;
  this.periodX=(int)(periodX + 0.5);
  this.periodY=(int)(periodY + 0.5);
  this.featureWidth=(int)(alg.getCanonicalWidth() * scale + 0.5);
  descriptions=new FastQueue<Desc>(alg.getDescriptionType(),true){
    @Override protected Desc createInstance(){
      return alg.createDescription();
    }
  }
;
}

Fixed version (ground truth):
@Override public void configure(double scale,double periodX,double periodY){
  this.radius=scale * scaleToRadius;
  this.periodX=(int)(periodX + 0.5);
  this.periodY=(int)(periodY + 0.5);
  this.featureWidth=(int)(alg.getCanonicalWidth() * scale + 0.5);
  descriptions=new FastQueue<Desc>(alg.getDescriptionType(),true){
    @Override protected Desc createInstance(){
      return alg.createDescription();
    }
  }
;
}
Program: 150859
Project: 150859
Buggy source:
/** 
 * <p> Creates a SURF descriptor.  SURF descriptors are invariant to illumination, orientation, and scale. BoofCV provides two variants. This SURF variant created here is designed for speed and sacrifices some stability. Different descriptors are produced for gray-scale and color images. </p>
 * @see DescribePointSurf
 * @param configSurf SURF configuration. Pass in null for default options.
 * @param imageType Type of input image.
 * @return SURF description extractor
 */
public static <T extends ImageSingleBand,II extends ImageSingleBand>DescribeImageDense<T,BrightFeature> surfFast(ConfigSurfDescribe.Speed configSurf,Class<T> imageType){
  DescribeRegionPoint<T,BrightFeature> surf=FactoryDescribeRegionPoint.surfFast(configSurf,imageType);
  return new GenericDenseDescribeImageDense<T,BrightFeature>(surf);
}

Fixed version (ground truth):
/** 
 * <p> Creates a SURF descriptor.  SURF descriptors are invariant to illumination, orientation, and scale. BoofCV provides two variants. This SURF variant created here is designed for speed and sacrifices some stability. Different descriptors are produced for gray-scale and color images. </p>
 * @see DescribePointSurf
 * @param configSurf SURF configuration. Pass in null for default options.
 * @param imageType Type of input image.
 * @return SURF description extractor
 */
public static <T extends ImageSingleBand,II extends ImageSingleBand>DescribeImageDense<T,BrightFeature> surfFast(ConfigSurfDescribe.Speed configSurf,Class<T> imageType){
  DescribeRegionPoint<T,BrightFeature> surf=FactoryDescribeRegionPoint.surfFast(configSurf,imageType);
  return new GenericDenseDescribeImageDense<T,BrightFeature>(surf,BoofDefaults.SURF_SCALE_TO_RADIUS);
}
Program: 150860
Project: 150860
Buggy source:
/** 
 * <p> Creates a SURF descriptor.  SURF descriptors are invariant to illumination, orientation, and scale. BoofCV provides two variants. The SURF variant created here is designed for stability.  Different descriptors are produced for gray-scale and color images. </p>
 * @see DescribePointSurf
 * @param configSurf SURF configuration. Pass in null for default options.
 * @param imageType Type of input image.
 * @return SURF description extractor
 */
public static <T extends ImageSingleBand,II extends ImageSingleBand>DescribeImageDense<T,BrightFeature> surfStable(ConfigSurfDescribe.Stability configSurf,Class<T> imageType){
  DescribeRegionPoint<T,BrightFeature> surf=FactoryDescribeRegionPoint.surfStable(configSurf,imageType);
  return new GenericDenseDescribeImageDense<T,BrightFeature>(surf);
}

Fixed version (ground truth):
/** 
 * <p> Creates a SURF descriptor.  SURF descriptors are invariant to illumination, orientation, and scale. BoofCV provides two variants. The SURF variant created here is designed for stability.  Different descriptors are produced for gray-scale and color images. </p>
 * @see DescribePointSurf
 * @param configSurf SURF configuration. Pass in null for default options.
 * @param imageType Type of input image.
 * @return SURF description extractor
 */
public static <T extends ImageSingleBand,II extends ImageSingleBand>DescribeImageDense<T,BrightFeature> surfStable(ConfigSurfDescribe.Stability configSurf,Class<T> imageType){
  DescribeRegionPoint<T,BrightFeature> surf=FactoryDescribeRegionPoint.surfStable(configSurf,imageType);
  return new GenericDenseDescribeImageDense<T,BrightFeature>(surf,BoofDefaults.SURF_SCALE_TO_RADIUS);
}
Program: 150861
Project: 150861
Buggy source:
public synchronized void viewUpdated(){
  if (contours == null)   return;
  int view=controlPanel.getSelectedView();
  Graphics2D g2=work.createGraphics();
  if (view == 0) {
    g2.drawImage(original,0,0,null);
  }
 else   if (view == 1) {
    VisualizeBinaryData.renderBinary(binary,false,work);
  }
 else {
    g2.setColor(Color.BLACK);
    g2.fillRect(0,0,work.getWidth(),work.getHeight());
  }
  SwingUtilities.invokeLater(new Runnable(){
    @Override public void run(){
      gui.setBufferedImage(work);
      gui.setScale(controlPanel.getZoom());
      gui.repaint();
      gui.requestFocusInWindow();
    }
  }
);
}

Fixed version (ground truth):
public synchronized void viewUpdated(){
  if (contours == null)   return;
  int view=controlPanel.getSelectedView();
  Graphics2D g2=work.createGraphics();
  if (view == 0) {
    g2.drawImage(original,0,0,null);
  }
 else   if (view == 1) {
    VisualizeBinaryData.renderBinary(binary,false,work);
  }
 else {
    g2.setColor(Color.BLACK);
    g2.fillRect(0,0,work.getWidth(),work.getHeight());
  }
  SwingUtilities.invokeLater(new Runnable(){
    @Override public void run(){
      gui.setScale(controlPanel.getZoom());
      gui.setBufferedImage(work);
    }
  }
);
}
Program: 150863
Project: 150863
Buggy source:
@Override public void run(){
  gui.setBufferedImage(work);
  gui.setScale(controlPanel.getZoom());
  gui.repaint();
  gui.requestFocusInWindow();
}

Fixed version (ground truth):
@Override public void run(){
  gui.setScale(controlPanel.getZoom());
  gui.setBufferedImage(work);
}
Program: 150865
Project: 150865
Buggy source:
/** 
 * Detects chessboard in the binary image.  Square corners must be disconnected. Returns true if a chessboard was found, false otherwise.
 * @param input Original input image.
 * @param binary Binary image of chessboard
 * @return True if successful.
 */
public boolean process(T input,ImageUInt8 binary){
  boundPolygon.vertexes.reset();
  detectorSquare.process(input,binary);
  FastQueue<Polygon2D_F64> found=detectorSquare.getFoundPolygons();
  clusters=s2c.process(found.toList());
  c2g.process(clusters);
  List<SquareGrid> grids=c2g.getGrids().toList();
  for (int i=0; i < grids.size(); i++) {
    SquareGrid grid=grids.get(i);
    if (grid.rows == numCols && grid.columns == numRows) {
      tools.transpose(grid);
    }
    if (grid.rows == numRows && grid.columns == numCols) {
      if (grid.get(0,0) == null) {
        if (grid.get(0,grid.columns - 1) != null) {
          tools.flipColumns(grid);
        }
 else {
          continue;
        }
      }
      putIntoCanonical(grid);
      return computeCalibrationPoints(grid);
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Detects chessboard in the binary image.  Square corners must be disconnected. Returns true if a chessboard was found, false otherwise.
 * @param input Original input image.
 * @param binary Binary image of chessboard
 * @return True if successful.
 */
public boolean process(T input,ImageUInt8 binary){
  boundPolygon.vertexes.reset();
  detectorSquare.process(input,binary);
  FastQueue<Polygon2D_F64> found=detectorSquare.getFoundPolygons();
  clusters=s2c.process(found.toList());
  c2g.process(clusters);
  List<SquareGrid> grids=c2g.getGrids().toList();
  for (int i=0; i < grids.size(); i++) {
    SquareGrid grid=grids.get(i);
    if (grid.rows == numCols && grid.columns == numRows) {
      tools.transpose(grid);
    }
    if (grid.rows == numRows && grid.columns == numCols) {
      if (grid.get(0,0) == null) {
        if (grid.get(0,-1) != null) {
          tools.flipColumns(grid);
        }
 else         if (grid.get(-1,0) != null) {
          tools.flipRows(grid);
        }
 else {
          continue;
        }
      }
      if (!ensureCCW(grid))       continue;
      putIntoCanonical(grid);
      return computeCalibrationPoints(grid);
    }
  }
  return false;
}
Program: 150866
Project: 150866
Buggy source:
/** 
 * Examines the grid and makes sure the (0,0) square is the closest one ot the top left corner. Only flip operations are allowed along symmetric axises
 */
void putIntoCanonical(SquareGrid grid){
  boolean rowOdd=grid.rows % 2 == 1;
  boolean colOdd=grid.columns % 2 == 1;
  if (colOdd) {
    double d0=grid.get(0,0).center.normSq();
    double d1=grid.get(0,-1).center.normSq();
    if (d1 < d0) {
      tools.flipColumns(grid);
    }
  }
  if (rowOdd) {
    double d0=grid.get(0,0).center.normSq();
    double d1=grid.get(-1,0).center.normSq();
    if (d1 < d0) {
      tools.flipRows(grid);
    }
  }
}

Fixed version (ground truth):
/** 
 * Examines the grid and makes sure the (0,0) square is the closest one ot the top left corner. Only flip operations are allowed along symmetric axises
 */
void putIntoCanonical(SquareGrid grid){
  boolean rowOdd=grid.rows % 2 == 1;
  boolean colOdd=grid.columns % 2 == 1;
  if (colOdd == rowOdd) {
    if (rowOdd && grid.rows == grid.columns) {
      int best=-1;
      double bestDistance=Double.MAX_VALUE;
      for (int i=0; i < 4; i++) {
        SquareNode n=grid.getCornerByIndex(i);
        double d=n.center.normSq();
        if (d < bestDistance) {
          best=i;
          bestDistance=d;
        }
      }
      for (int i=0; i < best; i++) {
        tools.rotateCCW(grid);
      }
    }
 else {
      double first=grid.get(0,0).center.normSq();
      double last=grid.getCornerByIndex(2).center.normSq();
      if (last < first) {
        tools.reverse(grid);
      }
    }
  }
}
Program: 150867
Project: 150867
Buggy source:
/** 
 * Configures chess board detector.
 * @param numRows Number of rows in square grid
 * @param numCols Number of columns in square grid
 * @param maxCornerDistance Maximum distance in pixels that two "overlapping" corners can be from each other.
 */
public DetectChessSquarePoints2(int numRows,int numCols,double maxCornerDistance,BinaryPolygonDetector<T> detectorSquare){
  this.maxCornerDistanceSq=maxCornerDistance * maxCornerDistance;
  this.numRows=numRows;
  this.numCols=numCols;
  this.detectorSquare=detectorSquare;
  s2c=new SquaresIntoCrossClusters(maxCornerDistance,0.5,-1);
  c2g=new CrossClustersIntoGrids();
}

Fixed version (ground truth):
/** 
 * Configures chess board detector.
 * @param numRows Number of rows in square grid
 * @param numCols Number of columns in square grid
 * @param maxCornerDistance Maximum distance in pixels that two "overlapping" corners can be from each other.
 */
public DetectChessSquarePoints2(int numRows,int numCols,double maxCornerDistance,BinaryPolygonDetector<T> detectorSquare){
  this.maxCornerDistanceSq=maxCornerDistance * maxCornerDistance;
  this.numRows=numRows;
  this.numCols=numCols;
  this.detectorSquare=detectorSquare;
  s2c=new SquaresIntoCrossClusters(maxCornerDistance,-1);
  c2g=new CrossClustersIntoGrids();
}
Program: 150868
Project: 150868
Buggy source:
/** 
 * Goes through each node and uses a nearest-neighbor search to find the closest nodes in its local neighborhood. It then checks those to see if it should connect
 */
void connectNodes(){
  setupSearch();
  int indexCornerList=0;
  for (int indexNode=0; indexNode < nodes.size(); indexNode++) {
    SquareNode n=nodes.get(indexNode);
    for (int indexLocal=0; indexLocal < 4; indexLocal++) {
      double[] point=searchPoints.get(indexCornerList++);
      searchResults.reset();
      search.findNearest(point,maxCornerDistance * maxCornerDistance,maxNeighbors + 1,searchResults);
      for (int indexResults=0; indexResults < searchResults.size(); indexResults++) {
        NnData<SquareNode> neighborData=searchResults.get(indexResults);
        SquareNode neighborNode=neighborData.data;
        if (neighborNode == n)         continue;
        int neighborCornerIndex=getCornerIndex(neighborNode,neighborData.point[0],neighborData.point[1]);
        considerConnect(n,indexLocal,neighborNode,neighborCornerIndex,neighborData.distance);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Goes through each node and uses a nearest-neighbor search to find the closest nodes in its local neighborhood. It then checks those to see if it should connect
 */
void connectNodes(){
  setupSearch();
  int indexCornerList=0;
  for (int indexNode=0; indexNode < nodes.size(); indexNode++) {
    SquareNode n=nodes.get(indexNode);
    for (int indexLocal=0; indexLocal < 4; indexLocal++) {
      double[] point=searchPoints.get(indexCornerList++);
      searchResults.reset();
      search.findNearest(point,maxCornerDistance * maxCornerDistance,maxNeighbors + 1,searchResults);
      for (int indexResults=0; indexResults < searchResults.size(); indexResults++) {
        NnData<SquareNode> neighborData=searchResults.get(indexResults);
        SquareNode neighborNode=neighborData.data;
        if (neighborNode == n)         continue;
        int neighborCornerIndex=getCornerIndex(neighborNode,neighborData.point[0],neighborData.point[1]);
        if (candidateIsMuchCloser(n,indexLocal,neighborNode,neighborCornerIndex,neighborData.distance))         considerConnect(n,indexLocal,neighborNode,neighborCornerIndex,neighborData.distance);
      }
    }
  }
}
Program: 150869
Project: 150869
Buggy source:
/** 
 * Declares data structures and configures algorithm
 * @param maxCornerDistance Maximum number of pixels apart two connected corners can be. UPDATE WHEN USED
 * @param maxNeighborLengthChange The maximum number of neighbors it will look at when connecting a node
 * @param maxNeighbors Max number of neighbors it will consider.  Try 4 or -1
 */
public SquaresIntoCrossClusters(double maxCornerDistance,double maxNeighborLengthChange,int maxNeighbors){
  this.maxCornerDistance=maxCornerDistance;
  this.maxNeighborLengthChange=maxNeighborLengthChange;
  this.maxNeighbors=maxNeighbors > 0 ? maxNeighbors : Integer.MAX_VALUE;
  if (this.maxNeighbors == Integer.MAX_VALUE) {
    this.maxNeighbors=Integer.MAX_VALUE - 1;
  }
  searchPoints=new FastQueue<double[]>(double[].class,true){
    @Override protected double[] createInstance(){
      return new double[2];
    }
  }
;
  search.init(2);
}

Fixed version (ground truth):
/** 
 * Declares data structures and configures algorithm
 * @param maxCornerDistance Maximum distance two corners can be in pixels.
 * @param maxNeighbors Max number of neighbors it will consider.  Try 4 or -1 for all
 */
public SquaresIntoCrossClusters(double maxCornerDistance,int maxNeighbors){
  this.maxCornerDistance=maxCornerDistance;
  this.maxNeighbors=maxNeighbors > 0 ? maxNeighbors : Integer.MAX_VALUE;
  if (this.maxNeighbors == Integer.MAX_VALUE) {
    this.maxNeighbors=Integer.MAX_VALUE - 1;
  }
  searchPoints=new FastQueue<double[]>(double[].class,true){
    @Override protected double[] createInstance(){
      return new double[2];
    }
  }
;
  search.init(2);
}
Program: 150870
Project: 150870
Buggy source:
/** 
 * Checks to see if the edge is intense enough or if it should be discarded as noise
 * @return true if the edge is strong enough
 */
private boolean checkPolygonEdge(Polygon2D_F64 polygon,boolean ccw){
  if (!edgeIntensity.computeEdge(polygon,ccw)) {
    if (verbose)     System.out.println("String_Node_Str");
    return false;
  }
  if (!edgeIntensity.checkIntensity(true,edgeThreshold)) {
    if (verbose) {
      double inside=edgeIntensity.getAverageInside();
      double outside=edgeIntensity.getAverageInside();
      System.out.println("String_Node_Str" + inside + "String_Node_Str"+ outside);
    }
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Checks to see if the edge is intense enough or if it should be discarded as noise
 * @return true if the edge is strong enough
 */
private boolean checkPolygonEdge(Polygon2D_F64 polygon,boolean ccw){
  if (!edgeIntensity.computeEdge(polygon,ccw)) {
    if (verbose)     System.out.println("String_Node_Str");
    return false;
  }
  if (!edgeIntensity.checkIntensity(true,edgeThreshold)) {
    if (verbose) {
      double inside=edgeIntensity.getAverageInside();
      double outside=edgeIntensity.getAverageOutside();
      System.out.println("String_Node_Str" + inside + "String_Node_Str"+ outside);
    }
    return false;
  }
  return true;
}
Program: 150871
Project: 150871
Buggy source:
public static void main(String[] args){
  DescribeImageDense<ImageUInt8,TupleDesc_F64> desc=(DescribeImageDense)FactoryDescribeImageDense.surfFast(null,ImageUInt8.class);
  desc.configure(DESC_SCALE,DESC_SKIP,DESC_SKIP);
  ComputeClusters<double[]> clusterer=FactoryClustering.kMeans_F64(null,MAX_KNN_ITERATIONS,20,1e-6);
  clusterer.setVerbose(true);
  NearestNeighbor<HistogramScene> nn=FactoryNearestNeighbor.exhaustive();
  ExampleClassifySceneKnn example=new ExampleClassifySceneKnn(desc,clusterer,nn);
  File trainingDir=new File(UtilIO.pathExample("String_Node_Str"));
  File testingDir=new File(UtilIO.pathExample("String_Node_Str"));
  if (!trainingDir.exists() || !testingDir.exists()) {
    String path=UtilIO.pathExample("String_Node_Str");
    System.err.println("String_Node_Str" + path + "String_Node_Str");
    System.err.println("String_Node_Str");
    System.exit(1);
  }
  example.loadSets(trainingDir,null,testingDir);
  example.learnAndSave();
  example.loadAndCreateClassifier();
  Confusion confusion=example.evaluateTest();
  confusion.getMatrix().print();
  System.out.println("String_Node_Str" + confusion.computeAccuracy());
  ShowImages.showWindow(new ConfusionMatrixPanel(confusion.getMatrix(),400,true),"String_Node_Str",true);
}

Fixed version (ground truth):
public static void main(String[] args){
  DescribeImageDense<ImageUInt8,TupleDesc_F64> desc=(DescribeImageDense)FactoryDescribeImageDense.surfFast(null,ImageUInt8.class);
  desc.configure(1,8,8);
  ComputeClusters<double[]> clusterer=FactoryClustering.kMeans_F64(null,MAX_KNN_ITERATIONS,20,1e-6);
  clusterer.setVerbose(true);
  NearestNeighbor<HistogramScene> nn=FactoryNearestNeighbor.exhaustive();
  ExampleClassifySceneKnn example=new ExampleClassifySceneKnn(desc,clusterer,nn);
  File trainingDir=new File(UtilIO.pathExample("String_Node_Str"));
  File testingDir=new File(UtilIO.pathExample("String_Node_Str"));
  if (!trainingDir.exists() || !testingDir.exists()) {
    String path=UtilIO.pathExample("String_Node_Str");
    System.err.println("String_Node_Str" + path + "String_Node_Str");
    System.err.println("String_Node_Str");
    System.exit(1);
  }
  example.loadSets(trainingDir,null,testingDir);
  example.learnAndSave();
  example.loadAndCreateClassifier();
  Confusion confusion=example.evaluateTest();
  confusion.getMatrix().print();
  System.out.println("String_Node_Str" + confusion.computeAccuracy());
  ShowImages.showWindow(new ConfusionMatrixPanel(confusion.getMatrix(),400,true),"String_Node_Str",true);
}
Program: 150872
Project: 150872
Buggy source:
@Override public void process(T input){
  if (scale == 1.0) {
    alg.setPeriodColumns(periodX);
    alg.setPeriodRows(periodY);
  }
 else {
    int width=(int)(input.width / scale + 0.5);
    int height=(int)(input.width / scale + 0.5);
    imageScaled.reshape(width,height);
    derivX.reshape(width,height);
    derivY.reshape(width,height);
    if (width < input.width) {
      AverageDownSampleOps.down(input,imageScaled);
    }
 else {
      scaleUp.setRefs(input,imageScaled).scaleExt().apply();
    }
    input=imageScaled;
    alg.setPeriodColumns(periodX / scale);
    alg.setPeriodRows(periodY / scale);
  }
  derivX.reshape(input.width,input.height);
  derivY.reshape(input.width,input.height);
  gradient.process(input,derivX,derivY);
  alg.setImageGradient(derivX,derivY);
  alg.process();
}

Fixed version (ground truth):
@Override public void process(T input){
  if (scale == 1.0) {
    alg.setPeriodColumns(periodX);
    alg.setPeriodRows(periodY);
  }
 else {
    int width=(int)(input.width / scale + 0.5);
    int height=(int)(input.height / scale + 0.5);
    imageScaled.reshape(width,height);
    derivX.reshape(width,height);
    derivY.reshape(width,height);
    if (width < input.width) {
      AverageDownSampleOps.down(input,imageScaled);
    }
 else {
      scaleUp.setRefs(input,imageScaled).scaleExt().apply();
    }
    input=imageScaled;
    alg.setPeriodColumns(periodX / scale);
    alg.setPeriodRows(periodY / scale);
  }
  derivX.reshape(input.width,input.height);
  derivY.reshape(input.width,input.height);
  gradient.process(input,derivX,derivY);
  alg.setImageGradient(derivX,derivY);
  alg.process();
}
Program: 150873
Project: 150873
Buggy source:
@Test public void checkDescriptorScale(){
  for (  Class type : imageTypes) {
    ImageSingleBand image=GeneralizedImageOps.createSingleBand(type,width,height);
    GImageMiscOps.fillUniform(image,rand,0,200);
    DescribeImageDense alg=createAlg(type);
    alg.configure(1,8,9);
    alg.process(image);
    int found10=alg.getDescriptions().size();
    alg.configure(1.5,8,9);
    alg.process(image);
    int found15=alg.getDescriptions().size();
    alg.configure(0.75,8,9);
    alg.process(image);
    int found07=alg.getDescriptions().size();
    assertTrue(found07 > found10);
    assertTrue(found10 > found15);
  }
}

Fixed version (ground truth):
@Test public void checkDescriptorScale(){
  for (  Class type : imageTypes) {
    ImageSingleBand image=GeneralizedImageOps.createSingleBand(type,width,height);
    GImageMiscOps.fillUniform(image,rand,0,200);
    DescribeImageDense alg=createAlg(type);
    alg.configure(1,8,9);
    alg.process(image);
    int found10=alg.getDescriptions().size();
    alg.configure(1.5,8,9);
    alg.process(image);
    int found15=alg.getDescriptions().size();
    alg.configure(0.75,8,9);
    alg.process(image);
    int found07a=alg.getDescriptions().size();
    alg.configure(0.75,8 * 0.75,9 * 0.75);
    alg.process(image);
    int found07b=alg.getDescriptions().size();
    assertTrue(found07a == found10);
    assertTrue(found07b > found10);
    assertTrue(found10 > found15);
  }
}
Program: 150875
Project: 150875
Buggy source:
void parseBinary(int index,String[] args){
  boolean robust=true;
  double size=1;
  int gridWidth=4;
  for (; index < args.length; index++) {
    String arg=args[index];
    if (!arg.startsWith("String_Node_Str")) {
      throw new RuntimeException("String_Node_Str");
    }
    splitFlag(arg);
    if (flagName.compareToIgnoreCase("String_Node_Str") == 0) {
      robust=Boolean.parseBoolean(parameters);
    }
 else     if (flagName.compareToIgnoreCase("String_Node_Str") == 0) {
      size=Double.parseDouble(parameters);
    }
 else     if (flagName.compareToIgnoreCase("String_Node_Str") == 0) {
      size=Integer.parseInt(parameters);
    }
 else {
      throw new RuntimeException("String_Node_Str" + flagName);
    }
  }
  System.out.println("String_Node_Str" + robust + "String_Node_Str"+ size+ "String_Node_Str"+ gridWidth);
  ConfigFiducialBinary configFid=new ConfigFiducialBinary();
  configFid.targetWidth=size;
  configFid.gridWidth=gridWidth;
  configFid.squareDetector.minimumEdgeIntensity=10;
  ConfigThreshold configThreshold;
  if (robust)   configThreshold=ConfigThreshold.local(ThresholdType.LOCAL_SQUARE,10);
 else   configThreshold=ConfigThreshold.fixed(DEFAULT_THRESHOLD);
  detector=FactoryFiducial.squareBinary(configFid,configThreshold,ImageUInt8.class);
}

Fixed version (ground truth):
void parseBinary(int index,String[] args){
  boolean robust=true;
  double size=1;
  int gridWidth=4;
  double borderWidth=0.25;
  for (; index < args.length; index++) {
    String arg=args[index];
    if (!arg.startsWith("String_Node_Str")) {
      throw new RuntimeException("String_Node_Str");
    }
    splitFlag(arg);
    if (flagName.compareToIgnoreCase("String_Node_Str") == 0) {
      robust=Boolean.parseBoolean(parameters);
    }
 else     if (flagName.compareToIgnoreCase("String_Node_Str") == 0) {
      size=Double.parseDouble(parameters);
    }
 else     if (flagName.compareToIgnoreCase("String_Node_Str") == 0) {
      gridWidth=Integer.parseInt(parameters);
    }
 else     if (flagName.compareToIgnoreCase("String_Node_Str") == 0) {
      borderWidth=Double.parseDouble(parameters);
    }
 else {
      throw new RuntimeException("String_Node_Str" + flagName);
    }
  }
  System.out.println("String_Node_Str" + robust + "String_Node_Str"+ size+ "String_Node_Str"+ gridWidth+ "String_Node_Str"+ borderWidth);
  ConfigFiducialBinary configFid=new ConfigFiducialBinary();
  configFid.targetWidth=size;
  configFid.gridWidth=gridWidth;
  configFid.squareDetector.minimumEdgeIntensity=10;
  configFid.borderWidthFraction=borderWidth;
  ConfigThreshold configThreshold;
  if (robust)   configThreshold=ConfigThreshold.local(ThresholdType.LOCAL_SQUARE,10);
 else   configThreshold=ConfigThreshold.fixed(DEFAULT_THRESHOLD);
  detector=FactoryFiducial.squareBinary(configFid,configThreshold,ImageUInt8.class);
}
Program: 150877
Project: 150877
Buggy source:
/** 
 * Captures calibration data live using a webcam and a GUI to assist the user
 */
public void handleWebcam(){
  Webcam webcam=Webcam.getWebcams().get(cameraId);
  if (desiredWidth > 0 && desiredHeight > 0)   UtilWebcamCapture.adjustResolution(webcam,desiredWidth,desiredHeight);
  webcam.open();
  ComputeGeometryScore quality=new ComputeGeometryScore(zeroSkew,detector.getLayout());
  AssistedCalibrationGui gui=new AssistedCalibrationGui(webcam.getViewSize());
  JFrame frame=ShowImages.showWindow(gui,"String_Node_Str",true);
  ImageFloat32 gray=new ImageFloat32(webcam.getViewSize().width,webcam.getViewSize().height);
  AssistedCalibration assisted=new AssistedCalibration(detector,quality,gui);
  assisted.init(gray.width,gray.height);
  BufferedImage image;
  while ((image=webcam.getImage()) != null && !assisted.isFinished()) {
    ConvertBufferedImage.convertFrom(image,gray);
    try {
      assisted.process(gray,image);
    }
 catch (    RuntimeException e) {
      System.err.println("String_Node_Str");
      UtilImageIO.saveImage(image,"String_Node_Str");
      throw e;
    }
  }
  webcam.close();
  if (assisted.isFinished()) {
    frame.setVisible(false);
    inputDirectory=AssistedCalibration.IMAGE_DIRECTORY;
    outputFileName=new File(inputDirectory,"String_Node_Str").getPath();
    handleDirectory();
  }
}

Fixed version (ground truth):
/** 
 * Captures calibration data live using a webcam and a GUI to assist the user
 */
public void handleWebcam(){
  Webcam webcam=Webcam.getWebcams().get(cameraId);
  if (desiredWidth > 0 && desiredHeight > 0)   UtilWebcamCapture.adjustResolution(webcam,desiredWidth,desiredHeight);
  webcam.open();
  ComputeGeometryScore quality=new ComputeGeometryScore(zeroSkew,detector.getLayout());
  AssistedCalibrationGui gui=new AssistedCalibrationGui(webcam.getViewSize());
  JFrame frame=ShowImages.showWindow(gui,"String_Node_Str",true);
  ImageFloat32 gray=new ImageFloat32(webcam.getViewSize().width,webcam.getViewSize().height);
  AssistedCalibration assisted=new AssistedCalibration(detector,quality,gui);
  assisted.init(gray.width,gray.height);
  BufferedImage image;
  while ((image=webcam.getImage()) != null && !assisted.isFinished()) {
    ConvertBufferedImage.convertFrom(image,gray);
    try {
      assisted.process(gray,image);
    }
 catch (    RuntimeException e) {
      System.err.println("String_Node_Str");
      UtilImageIO.saveImage(image,"String_Node_Str");
      throw e;
    }
  }
  webcam.close();
  if (assisted.isFinished()) {
    frame.setVisible(false);
    inputDirectory=AssistedCalibration.IMAGE_DIRECTORY;
    outputFileName=new File(AssistedCalibration.OUTPUT_DIRECTORY,"String_Node_Str").getPath();
    handleDirectory();
  }
}
Program: 150879
Project: 150879
Buggy source:
/** 
 * Finds the point between indexStart and the end point which is the greater distance from the line (set up prior to calling).  Returns the index 0f the distance is less than tolerance, otherwise -1
 */
protected int selectSplitOffset(int indexStart,int length){
  int bestOffset=-1;
  int indexEnd=(indexStart + length) % N;
  Point2D_I32 startPt=contour.get(indexStart);
  Point2D_I32 endPt=contour.get(indexEnd);
  line.p.set(startPt.x,startPt.y);
  line.slope.set(endPt.x - startPt.x,endPt.y - startPt.y);
  double bestDistanceSq=0;
  double toleranceSplitSq=splitThresholdSq(contour.get(indexStart),contour.get(indexEnd));
  length-=minimumSideLengthPixel;
  for (int i=1 + minimumSideLengthPixel; i < length; i++) {
    Point2D_I32 b=contour.get((indexStart + i) % N);
    point2D.set(b.x,b.y);
    double dist=Distance2D_F64.distanceSq(line,point2D);
    if (dist > bestDistanceSq) {
      bestDistanceSq=dist;
      bestOffset=i;
    }
  }
  if (bestDistanceSq > toleranceSplitSq) {
    return bestOffset;
  }
 else {
    return -1;
  }
}

Fixed version (ground truth):
/** 
 * Finds the point between indexStart and the end point which is the greater distance from the line (set up prior to calling).  Returns the index 0f the distance is less than tolerance, otherwise -1
 */
protected int selectSplitOffset(int indexStart,int length){
  int bestOffset=-1;
  int indexEnd=(indexStart + length) % N;
  Point2D_I32 startPt=contour.get(indexStart);
  Point2D_I32 endPt=contour.get(indexEnd);
  line.p.set(startPt.x,startPt.y);
  line.slope.set(endPt.x - startPt.x,endPt.y - startPt.y);
  double bestDistanceSq=0;
  double toleranceSplitSq=splitThresholdSq(contour.get(indexStart),contour.get(indexEnd));
  length-=2 * minimumSideLengthPixel;
  for (int i=1 + minimumSideLengthPixel; i < length; i++) {
    Point2D_I32 b=contour.get((indexStart + i) % N);
    point2D.set(b.x,b.y);
    double dist=Distance2D_F64.distanceSq(line,point2D);
    if (dist > bestDistanceSq) {
      bestDistanceSq=dist;
      bestOffset=i;
    }
  }
  if (bestDistanceSq > toleranceSplitSq) {
    return bestOffset;
  }
 else {
    return -1;
  }
}
Program: 150880
Project: 150880
Buggy source:
private void findContour(boolean black){
  ImageUInt8 binary=new ImageUInt8(image.width,image.height);
  GThresholdImageOps.threshold(image,binary,40,black);
  contour=BinaryImageOps.contour(binary,ConnectRule.FOUR,null).get(0).external;
  List<PointIndex_I32> corners=ShapeFittingOps.fitPolygon(contour,true,0.05,5.0,10);
  split=new GrowQueue_I32(corners.size());
  for (int i=0; i < corners.size(); i++) {
    split.add(corners.get(i).index);
  }
}

Fixed version (ground truth):
private void findContour(boolean black){
  ImageUInt8 binary=new ImageUInt8(image.width,image.height);
  GThresholdImageOps.threshold(image,binary,40,black);
  contour=BinaryImageOps.contour(binary,ConnectRule.FOUR,null).get(0).external;
  List<PointIndex_I32> corners=ShapeFittingOps.fitPolygon(contour,true,0.05,0.1,10);
  split=new GrowQueue_I32(corners.size());
  for (int i=0; i < corners.size(); i++) {
    split.add(corners.get(i).index);
  }
}
Program: 150881
Project: 150881
Buggy source:
@Test public void mergeLines(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.05,0,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(9 - i,1));
  alg.N=alg.contour.size();
  alg.splits.add(0);
  alg.splits.add(5);
  alg.splits.add(9);
  alg.splits.add(10);
  alg.splits.add(15);
  alg.splits.add(19);
  assertTrue(alg.mergeSegments());
  assertTrue(matchSplitsToExpected(new int[]{0,9,10,19},alg.splits));
  alg.splits.reset();
  alg.splits.add(5);
  alg.splits.add(9);
  alg.splits.add(10);
  alg.splits.add(15);
  alg.splits.add(19);
  alg.splits.add(0);
  assertTrue(alg.mergeSegments());
  assertTrue(matchSplitsToExpected(new int[]{9,10,19,0},alg.splits));
}

Fixed version (ground truth):
@Test public void mergeLines(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.05,MINIMUM_SPLIT_FRACTION,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(9 - i,3));
  alg.N=alg.contour.size();
  alg.splits.add(0);
  alg.splits.add(5);
  alg.splits.add(9);
  alg.splits.add(10);
  alg.splits.add(15);
  alg.splits.add(19);
  assertTrue(alg.mergeSegments());
  assertTrue(matchSplitsToExpected(new int[]{0,9,10,19},alg.splits));
  alg.splits.reset();
  alg.splits.add(5);
  alg.splits.add(9);
  alg.splits.add(10);
  alg.splits.add(15);
  alg.splits.add(19);
  alg.splits.add(0);
  assertTrue(alg.mergeSegments());
  assertTrue(matchSplitsToExpected(new int[]{9,10,19,0},alg.splits));
}
Program: 150882
Project: 150882
Buggy source:
@Test public void splitSegments(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.001,1,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=5;
  alg.N=alg.contour.size();
  alg.splits.add(0);
  alg.splits.add(6);
  assertTrue(alg.splitSegments());
  assertTrue(matchSplitsToExpected(new int[]{0,4,6},alg.splits));
}

Fixed version (ground truth):
@Test public void splitSegments(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.001,MINIMUM_SPLIT_FRACTION,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=5;
  alg.N=alg.contour.size();
  alg.splits.add(0);
  alg.splits.add(6);
  assertTrue(alg.splitSegments());
  assertTrue(matchSplitsToExpected(new int[]{0,4,6},alg.splits));
}
Program: 150883
Project: 150883
Buggy source:
@Test public void selectFarthest(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,1,100);
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(i,0));
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(9 - i,1));
  int found=alg.selectFarthest(contour);
  assertEquals(0,found);
  for (int offset=1; offset < 5; offset++) {
    List<Point2D_I32> adjusted=shiftContour(contour,offset);
    found=alg.selectFarthest(adjusted);
    assertEquals(9 - offset,found);
  }
}

Fixed version (ground truth):
@Test public void selectFarthest(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,MINIMUM_SPLIT_FRACTION,100);
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(i,0));
  for (int i=0; i < 10; i++)   contour.add(new Point2D_I32(9 - i,1));
  int found=alg.selectFarthest(contour);
  assertEquals(0,found);
  for (int offset=1; offset < 5; offset++) {
    List<Point2D_I32> adjusted=shiftContour(contour,offset);
    found=alg.selectFarthest(adjusted);
    assertEquals(9 - offset,found);
  }
}
Program: 150884
Project: 150884
Buggy source:
@Test public void selectSplitOffset(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.001,1,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=10;
  alg.N=alg.contour.size();
  alg.line.slope.x=1;
  int found=alg.selectSplitOffset(0,9);
  assertEquals(4,found);
  found=alg.selectSplitOffset(0,5);
  assertEquals(4,found);
  found=alg.selectSplitOffset(0,4);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(0,3);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(3,5);
  assertEquals(1,found);
  found=alg.selectSplitOffset(5,6);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(5,8);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(5,10);
  assertEquals(9,found);
  found=alg.selectSplitOffset(9,8);
  assertEquals(5,found);
  fail("String_Node_Str");
}

Fixed version (ground truth):
@Test public void selectSplitOffset(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.001,MINIMUM_SPLIT_FRACTION,100);
  alg.contour=new ArrayList<Point2D_I32>();
  for (int i=0; i < 10; i++)   alg.contour.add(new Point2D_I32(i,0));
  alg.contour.get(4).y=10;
  alg.N=alg.contour.size();
  alg.line.slope.x=1;
  int found=alg.selectSplitOffset(0,9);
  assertEquals(4,found);
  found=alg.selectSplitOffset(0,5);
  assertEquals(4,found);
  found=alg.selectSplitOffset(0,4);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(0,3);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(3,5);
  assertEquals(1,found);
  found=alg.selectSplitOffset(5,6);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(5,8);
  assertEquals(-1,found);
  found=alg.selectSplitOffset(5,10);
  assertEquals(9,found);
  found=alg.selectSplitOffset(9,8);
  assertEquals(5,found);
  fail("String_Node_Str");
}
Program: 150885
Project: 150885
Buggy source:
/** 
 * Multiple splits are required
 */
@Test public void splitPixels_multiple(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.001,1,100);
  alg.contour=new ArrayList<Point2D_I32>();
  alg.contour.add(new Point2D_I32(0,0));
  alg.contour.add(new Point2D_I32(10,10));
  alg.contour.add(new Point2D_I32(20,20));
  alg.contour.add(new Point2D_I32(30,30));
  alg.contour.add(new Point2D_I32(50,20));
  alg.contour.add(new Point2D_I32(60,10));
  alg.contour.add(new Point2D_I32(70,0));
  alg.N=alg.contour.size();
  alg.splitPixels(0,alg.N - 1);
  assertEquals(2,alg.splits.size);
  assertEquals(3,alg.splits.data[0]);
  assertEquals(4,alg.splits.data[1]);
  alg.contour=shiftContour(alg.contour,2);
  alg.splits.reset();
  alg.splitPixels(alg.N - 2,alg.N - 1);
  assertEquals(2,alg.splits.size);
  assertEquals(1,alg.splits.data[0]);
  assertEquals(2,alg.splits.data[1]);
}

Fixed version (ground truth):
/** 
 * Multiple splits are required
 */
@Test public void splitPixels_multiple(){
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.001,MINIMUM_SPLIT_FRACTION,100);
  alg.contour=new ArrayList<Point2D_I32>();
  alg.contour.add(new Point2D_I32(0,0));
  alg.contour.add(new Point2D_I32(10,10));
  alg.contour.add(new Point2D_I32(20,20));
  alg.contour.add(new Point2D_I32(30,30));
  alg.contour.add(new Point2D_I32(50,20));
  alg.contour.add(new Point2D_I32(60,10));
  alg.contour.add(new Point2D_I32(70,0));
  alg.N=alg.contour.size();
  alg.splitPixels(0,alg.N - 1);
  assertEquals(2,alg.splits.size);
  assertEquals(3,alg.splits.data[0]);
  assertEquals(4,alg.splits.data[1]);
  alg.contour=shiftContour(alg.contour,2);
  alg.splits.reset();
  alg.splitPixels(alg.N - 2,alg.N - 1);
  assertEquals(2,alg.splits.size);
  assertEquals(1,alg.splits.data[0]);
  assertEquals(2,alg.splits.data[1]);
}
Program: 150886
Project: 150886
Buggy source:
/** 
 * Tests contours with zero and one points in them
 */
@Test public void checkZeroOne(){
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,5,100);
  alg.process(contour);
  assertEquals(0,alg.getSplits().size);
  contour.add(new Point2D_I32(2,3));
  alg.process(contour);
  assertEquals(0,alg.getSplits().size);
}

Fixed version (ground truth):
/** 
 * Tests contours with zero and one points in them
 */
@Test public void checkZeroOne(){
  List<Point2D_I32> contour=new ArrayList<Point2D_I32>();
  SplitMergeLineFitLoop alg=new SplitMergeLineFitLoop(0.15,MINIMUM_SPLIT_FRACTION,100);
  alg.process(contour);
  assertEquals(0,alg.getSplits().size);
  contour.add(new Point2D_I32(2,3));
  alg.process(contour);
  assertEquals(0,alg.getSplits().size);
}