From 8497883f602321493e414a4517dbf70081a82aee Mon Sep 17 00:00:00 2001 From: tylermorganwall Date: Sat, 2 Dec 2023 14:18:54 -0500 Subject: [PATCH] -Update tests to use near-identical image comparison --- tests/testthat/test-plot_image.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-plot_image.R b/tests/testthat/test-plot_image.R index d79edd3..fc08283 100644 --- a/tests/testthat/test-plot_image.R +++ b/tests/testthat/test-plot_image.R @@ -5,10 +5,16 @@ save_test_png = function(code, path) { path } -compare_image = function(path1, path2) { +compare_image = function(path1, path2, quantile_diff = 0.001) { image1 = png::readPNG(path1) image2 = png::readPNG(path2) - return(identical(image1, image2)) + # No alpha + diffs = abs(image2 - image1)[,,1:3] + #Ignore small differences + diffs = diffs[order(diffs)] + mostly_identical = diffs[length(diffs) * quantile_diff] == 0 + diffs_are_minor = max(diffs) < 0.1 + return(mostly_identical && diffs_are_minor) }