Program: 170408
Project: 170408
Buggy source:
@Test public void testScaleMultiLevelImageWithDifferentLevelCounts(){
  Band targetBand=new Band("String_Node_Str",ProductData.TYPE_INT32,200,200);
  int masterLevelCount=5;
  int sourceLevelCount=3;
  MultiLevelImage masterImage=createNewMultiLevelMasterImage(masterLevelCount,200,200);
  targetBand.setSourceImage(masterImage);
  MultiLevelImage sourceImage=createSourceImage(sourceLevelCount,100,100);
  float[] scalings=new float[]{((float)targetBand.getRasterWidth()) / sourceImage.getWidth(),((float)targetBand.getRasterHeight()) / sourceImage.getHeight()};
  float[] translationsBeforeScaling=new float[]{0f,0f};
  final RenderingHints renderingHints=new RenderingHints(JAI.KEY_BORDER_EXTENDER,BorderExtender.createInstance(BorderExtender.BORDER_COPY));
  MultiLevelImage scaledImage=SourceImageScaler.scaleMultiLevelImage(masterImage,sourceImage,scalings,translationsBeforeScaling,new float[]{0f,0f},renderingHints,Double.NaN,Interpolation.getInstance(Interpolation.INTERP_NEAREST));
  final Rectangle targetBounds=targetBand.getSourceImage().getBounds();
  assertEquals(targetBand.getRasterWidth(),scaledImage.getWidth());
  assertEquals(targetBand.getRasterHeight(),scaledImage.getHeight());
  assertEquals(masterLevelCount,scaledImage.getModel().getLevelCount());
  for (int i=0; i < masterLevelCount; i++) {
    final RenderedImage masterImageAtLevel=((MultiLevelImage)targetBand.getSourceImage()).getImage(i);
    final RenderedImage scaledImageAtLevel=scaledImage.getImage(i);
    assertEquals(masterImageAtLevel.getWidth(),scaledImageAtLevel.getWidth());
    assertEquals(masterImageAtLevel.getHeight(),scaledImageAtLevel.getHeight());
  }
  assertEquals(MAX_USHORT,scaledImage.getData().getSample(0,0,0));
  assertEquals(MAX_USHORT,scaledImage.getData().getSample(targetBounds.width - 1,0,0));
  assertEquals(MAX_USHORT,scaledImage.getData().getSample(0,targetBounds.height - 1,0));
  assertEquals(MAX_USHORT,scaledImage.getData().getSample(targetBounds.width - 1,targetBounds.height - 1,0));
}

Fixed version (ground truth):
@Test public void testScaleMultiLevelImageWithDifferentLevelCounts(){
  MultiLevelImage masterImage=createNewMultiLevelMasterImage(levelCount,200,200);
  targetBand.setSourceImage(masterImage);
  int sourceLevelCount=3;
  MultiLevelImage sourceImage=createSourceImage(sourceLevelCount,100,100);
  MultiLevelImage scaledImage=SourceImageScaler.scaleMultiLevelImage(masterImage,sourceImage,scalings,translationsBeforeScaling,new float[]{0f,0f},renderingHints,Double.NaN,Interpolation.getInstance(Interpolation.INTERP_NEAREST));
  final Rectangle targetBounds=targetBand.getSourceImage().getBounds();
  assertEquals(targetBand.getRasterWidth(),scaledImage.getWidth());
  assertEquals(targetBand.getRasterHeight(),scaledImage.getHeight());
  assertEquals(levelCount,scaledImage.getModel().getLevelCount());
  for (int i=0; i < levelCount; i++) {
    final RenderedImage masterImageAtLevel=((MultiLevelImage)targetBand.getSourceImage()).getImage(i);
    final RenderedImage scaledImageAtLevel=scaledImage.getImage(i);
    assertEquals(masterImageAtLevel.getWidth(),scaledImageAtLevel.getWidth());
    assertEquals(masterImageAtLevel.getHeight(),scaledImageAtLevel.getHeight());
  }
  assertEquals(MAX_USHORT,scaledImage.getData().getSample(0,0,0));
  assertEquals(MAX_USHORT,scaledImage.getData().getSample(targetBounds.width - 1,0,0));
  assertEquals(MAX_USHORT,scaledImage.getData().getSample(0,targetBounds.height - 1,0));
  assertEquals(MAX_USHORT,scaledImage.getData().getSample(targetBounds.width - 1,targetBounds.height - 1,0));
}