Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ public static float getDifferencePercent(BufferedImage img1, BufferedImage img2)
long diff = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
diff += pixelDiff(img1.getRGB(x, y), img2.getRGB(x, y));
if(img1.getRGB(x, y) != img2.getRGB(x, y))
diff++;
}
}
long maxDiff = 3L * 255 * width * height;
long maxDiff = (long) width * height;

return (float) (100.0 * diff / maxDiff);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public void shouldProperlyHandleIssue196() {

//then
assertEquals(MISMATCH, imageComparisonResult.getImageComparisonState());
assertEquals(0.4274517595767975, imageComparisonResult.getDifferencePercent());
assertEquals(0.6673570275306702, imageComparisonResult.getDifferencePercent());
assertImagesEqual(expectedImage, imageComparisonResult.getResult());
}

Expand Down Expand Up @@ -519,8 +519,22 @@ public void shouldProperlyCompareMisSizedImages() {
//then
assertEquals(SIZE_MISMATCH, imageComparisonResult.getImageComparisonState());
assertEquals(0, imageComparisonResult.getRectangles().size());
boolean differenceLessThan2 = imageComparisonResult.getDifferencePercent() < 2;
assertTrue(differenceLessThan2);
assertTrue(imageComparisonResult.getDifferencePercent() <= 99.39796);
}

@DisplayName("Should properly get and set percentage of differences #233")
@Test
public void shouldProperlySetPercentageOfDifferences() {
//given
ImageComparison imageComparison = new ImageComparison("expected#196.png", "actual#196.png");

//when
float difPercent = imageComparison.compareImages().getDifferencePercent();
ImageComparisonResult imageComparisonResult = imageComparison.setAllowingPercentOfDifferentPixels(difPercent)
.compareImages();

//then
assertEquals(MATCH, imageComparisonResult.getImageComparisonState());
}

private void assertImagesEqual(BufferedImage expected, BufferedImage actual) {
Expand Down