// Path: core/src/main/java/de/otto/jlineup/config/JobConfig.java
// public static final float DEFAULT_MAX_COLOR_DISTANCE = 2.3f;
// 
// Path: core/src/main/java/de/otto/jlineup/image/ImageService.java
// public static boolean bufferedImagesEqual(BufferedImage image1, BufferedImage image2) {
//     if (image1.getWidth() == image2.getWidth() && image1.getHeight() == image2.getHeight()) {
//         for (int xPosition = 0; xPosition < image1.getWidth(); xPosition++) {
//             for (int yPosition = 0; yPosition < image1.getHeight(); yPosition++) {
//                 if (image1.getRGB(xPosition, yPosition) != image2.getRGB(xPosition, yPosition))
//                     return false;
//             }
//         }
//     } else {
//         return false;
//     }
//     return true;
// }


import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import static de.otto.jlineup.config.JobConfig.DEFAULT_MAX_COLOR_DISTANCE;
import static de.otto.jlineup.image.ImageService.bufferedImagesEqual;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;

        //then
        assertThat(result.getAcceptedDifferentPixels(), is(0));
        assertThat(result.getDifference(), greaterThan(0d));
        assertThat(bufferedImagesEqual(referenceImageBuffer, result.getDifferenceImage().orElse(null)), is(true));
    }

    @Test
    public void shouldIgnoreSlightDifferencesInColorSpaceInDefaultNonStrictMode() throws IOException {
        //given
        final int viewportHeight = 800;
        final BufferedImage beforeImageBuffer = ImageIO.read(new File("src/test/resources/screenshots/cases/chrome_rounded_edges_before.png"));
        final BufferedImage afterImageBuffer = ImageIO.read(new File("src/test/resources/screenshots/cases/chrome_rounded_edges_after.png"));

        //when
        ImageService.ImageComparisonResult result = testee.compareImages(beforeImageBuffer, afterImageBuffer, viewportHeight, false, false, DEFAULT_MAX_COLOR_DISTANCE);

        //then
        assertThat(result.getDifference(), is(0.0));
        assertThat(result.getAcceptedDifferentPixels(), is(5));
    }

    @Test
    public void shouldIgnoreRoundedEdgeAntialiasDifference() throws IOException {
        //given
        final int viewportHeight = 800;
        final BufferedImage beforeImageBuffer = ImageIO.read(new File("src/test/resources/screenshots/cases/shoppromo_before.png"));
        final BufferedImage afterImageBuffer = ImageIO.read(new File("src/test/resources/screenshots/cases/shoppromo_after.png"));

        //when
// Path: core/src/main/java/de/otto/jlineup/config/JobConfig.java
// public static final float DEFAULT_MAX_COLOR_DISTANCE = 2.3f;
// 
// Path: core/src/main/java/de/otto/jlineup/image/ImageService.java
// public static boolean bufferedImagesEqual(BufferedImage image1, BufferedImage image2) {
//     if (image1.getWidth() == image2.getWidth() && image1.getHeight() == image2.getHeight()) {
//         for (int xPosition = 0; xPosition < image1.getWidth(); xPosition++) {
//             for (int yPosition = 0; yPosition < image1.getHeight(); yPosition++) {
//                 if (image1.getRGB(xPosition, yPosition) != image2.getRGB(xPosition, yPosition))
//                     return false;
//             }
//         }
//     } else {
//         return false;
//     }
//     return true;
// }


// Path: core/src/test/java/de/otto/jlineup/image/ImageServiceTest.java
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import static de.otto.jlineup.config.JobConfig.DEFAULT_MAX_COLOR_DISTANCE;
import static de.otto.jlineup.image.ImageService.bufferedImagesEqual;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;


        //then
        assertThat(result.getAcceptedDifferentPixels(), is(0));
        assertThat(result.getDifference(), greaterThan(0d));
        assertThat(bufferedImagesEqual(referenceImageBuffer, result.getDifferenceImage().orElse(null)), is(true));
    }

    @Test
    public void shouldIgnoreSlightDifferencesInColorSpaceInDefaultNonStrictMode() throws IOException {
        //given
        final int viewportHeight = 800;
        final BufferedImage beforeImageBuffer = ImageIO.read(new File("src/test/resources/screenshots/cases/chrome_rounded_edges_before.png"));
        final BufferedImage afterImageBuffer = ImageIO.read(new File("src/test/resources/screenshots/cases/chrome_rounded_edges_after.png"));

        //when
        ImageService.ImageComparisonResult result = testee.compareImages(beforeImageBuffer, afterImageBuffer, viewportHeight, false, false, DEFAULT_MAX_COLOR_DISTANCE);

        //then
        assertThat(result.getDifference(), is(0.0));
        assertThat(result.getAcceptedDifferentPixels(), is(5));
    }

    @Test
    public void shouldIgnoreRoundedEdgeAntialiasDifference() throws IOException {
        //given
        final int viewportHeight = 800;
        final BufferedImage beforeImageBuffer = ImageIO.read(new File("src/test/resources/screenshots/cases/shoppromo_before.png"));
        final BufferedImage afterImageBuffer = ImageIO.read(new File("src/test/resources/screenshots/cases/shoppromo_after.png"));

        //when
        ImageService.ImageComparisonResult result = testee.compareImages(beforeImageBuffer, afterImageBuffer, viewportHeight, true, false, DEFAULT_MAX_COLOR_DISTANCE);