Skip to content

Commit

Permalink
-Turn off golden tests (too inconsistent across systems)
Browse files Browse the repository at this point in the history
-Improve docs
  • Loading branch information
tylermorganwall committed Nov 26, 2023
1 parent bb067e6 commit 972b3ef
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 58 deletions.
6 changes: 3 additions & 3 deletions R/render_distance.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#'@examples
#'if(rayimage:::run_documentation()){
#'#Measure distance to
#'image(render_boolean_distance(volcano > 150))
#'image(render_boolean_distance(volcano < 150))
#'plot_image(render_boolean_distance(t(volcano) > 150))
#'plot_image(render_boolean_distance(t(volcano) < 150))
#'}
#'if(rayimage:::run_documentation()){
#'#If we want to rescale this to zero to one (to visualize like an image), set rescale=TRUE
#'plot_image(render_boolean_distance(volcano > 150,rescale=TRUE))
#'plot_image(render_boolean_distance(t(volcano) > 150,rescale=TRUE))
#'}
render_boolean_distance = function(boolean, rescale = FALSE) {
if(any(is.na(boolean))) {
Expand Down
6 changes: 3 additions & 3 deletions man/render_boolean_distance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 53 additions & 52 deletions tests/testthat/test-plot_image.R
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
save_test_png = function(code, path) {
grDevices::png(filename=path, width=500, height=400)
code
dev.off()
path
}

compare_image = function(path1, path2) {
image1 = png::readPNG(path1)
image2 = png::readPNG(path2)
return(identical(image1, image2))
}

run_tests = function(func, argument_grid, plot_prefix="", ...) {
stopifnot(inherits(argument_grid,"data.frame"))
for(i in seq_len(nrow(argument_grid))){
args = unlist(argument_grid[i,], recursive = FALSE)
test_filename = sprintf("%s_test%i.png",
plot_prefix , i)
path = tempfile(fileext = ".png")

args = append(args, ...)
# args = append(args, list(filename = path))
# browser()
save_test_png(do.call(func, args = args), path) |>
suppressMessages() |>
suppressWarnings() |>
expect_snapshot_file(name = test_filename, compare = compare_image)
}
}

test_that("Checking plot_image", {
plt_img_args = expand.grid(rotate = list(0,90,180,270),
draw_grid = list(FALSE, TRUE),
asp = list(0.5,1,2),
new_page = list(TRUE, FALSE))

run_tests("plot_image", plt_img_args, plot_prefix = "plt_img",
list(input = dragon))
})

test_that("Checking plot_image_grid", {
plt_img_args = expand.grid(input_list = list(list(dragon, NULL, NULL, dragon)),
dim = list(c(1,1),
c(2,2),
c(1,2),
c(2,1)),
draw_grid = list(FALSE, TRUE),
asp = list(c(0.5,1,2,3)))

run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid", list())
})
# save_test_png = function(code, path) {
# grDevices::png(filename=path, width=500, height=400)
# code
# dev.off()
# path
# }
#
# compare_image = function(path1, path2) {
# image1 = png::readPNG(path1)
# image2 = png::readPNG(path2)
# return(identical(image1, image2))
# }
#
# run_tests = function(func, argument_grid, plot_prefix="", ...) {
# stopifnot(inherits(argument_grid,"data.frame"))
# for(i in seq_len(nrow(argument_grid))){
# args = unlist(argument_grid[i,], recursive = FALSE)
# test_filename = sprintf("%s_test%i.png",
# plot_prefix , i)
# path = tempfile(fileext = ".png")
#
# args = append(args, ...)
# # args = append(args, list(filename = path))
# # browser()
# save_test_png(do.call(func, args = args), path) |>
# suppressMessages() |>
# suppressWarnings() |>
# expect_snapshot_file(name = test_filename, compare = compare_image)
# }
# }
#
# test_that("Checking plot_image", {
# plt_img_args = expand.grid(rotate = list(0,90,180,270),
# draw_grid = list(FALSE, TRUE),
# asp = list(0.5,1,2),
# new_page = list(TRUE, FALSE))
#
# run_tests("plot_image", plt_img_args, plot_prefix = "plt_img",
# list(input = dragon))
# })
#
# test_that("Checking plot_image_grid", {
# plt_img_args = expand.grid(input_list = list(list(dragon, NULL, NULL, dragon)),
# dim = list(c(1,1),
# c(2,2),
# c(1,2),
# c(2,1)),
# draw_grid = list(FALSE, TRUE),
# asp = list(c(0.5,1,2,3)))
# plt_img_args = plt_img_args[-6,] #False positive
#
# run_tests("plot_image_grid", plt_img_args, plot_prefix = "plt_img_grid", list())
# })

0 comments on commit 972b3ef

Please sign in to comment.