From 2e5ebb392b3fc5587adb49a8e1cee2009a509963 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 20 Aug 2024 15:01:13 -0400 Subject: [PATCH] update image assert for testing --- buildNumber.properties | 4 +-- .../java/testutils/TestRenderingUtils.java | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/buildNumber.properties b/buildNumber.properties index 4f784a29..24f95762 100644 --- a/buildNumber.properties +++ b/buildNumber.properties @@ -1,3 +1,3 @@ #maven.buildNumber.plugin properties file -#Mon Aug 19 13:16:30 EDT 2024 -buildNumber=280 +#Tue Aug 20 15:00:55 EDT 2024 +buildNumber=281 diff --git a/src/test/java/testutils/TestRenderingUtils.java b/src/test/java/testutils/TestRenderingUtils.java index d986f8ed..862d9b47 100644 --- a/src/test/java/testutils/TestRenderingUtils.java +++ b/src/test/java/testutils/TestRenderingUtils.java @@ -15,6 +15,11 @@ import electrosphere.renderer.RenderingEngine; * Utilities for comparing renders */ public class TestRenderingUtils { + + /** + * The threshold at which we say the colors are 'close enough' + */ + static final int COLOR_COMPARE_THRESHOLD = 3; /** * Asserts that the most recent render matches the image stored at the provided filepath @@ -41,10 +46,28 @@ public class TestRenderingUtils { //pixel-by-pixel check for(int x = 0; x < testData.getWidth(); x++){ for(int y = 0; y < testData.getHeight(); y++){ - if(testData.getRGB(x, y) != screenshot.getRGB(x, y)){ + + //get from-disk rgba + int sourceRed = testData.getRGB(x, y) & 0xff; + int sourceGreen = (testData.getRGB(x, y) & 0xff00) >> 8; + int sourceBlue = (testData.getRGB(x, y) & 0xff0000) >> 16; + int sourceAlpha = (testData.getRGB(x, y) & 0xff000000) >>> 24; + + //get from-render rgba + int renderRed = screenshot.getRGB(x, y) & 0xff; + int renderGreen = (screenshot.getRGB(x, y) & 0xff00) >> 8; + int renderBlue = (screenshot.getRGB(x, y) & 0xff0000) >> 16; + int renderAlpha = (screenshot.getRGB(x, y) & 0xff000000) >>> 24; + + if( + Math.abs(sourceRed - renderRed) > COLOR_COMPARE_THRESHOLD || + Math.abs(sourceGreen - renderGreen) > COLOR_COMPARE_THRESHOLD || + Math.abs(sourceBlue - renderBlue) > COLOR_COMPARE_THRESHOLD || + Math.abs(sourceAlpha - renderAlpha) > COLOR_COMPARE_THRESHOLD + ){ onFailure.run(); + fail("Colors aren't approximately the same!"); } - assertEquals(testData.getRGB(x, y),screenshot.getRGB(x, y)); } } }