Skip to content

Commit

Permalink
-Update tests to use near-identical image comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermorganwall committed Dec 2, 2023
1 parent 706174d commit 8497883
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/testthat/test-plot_image.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down

0 comments on commit 8497883

Please sign in to comment.