Skip to content

Commit

Permalink
-Fix internal docs for CHECK
Browse files Browse the repository at this point in the history
-Try tests only on macos
  • Loading branch information
tylermorganwall committed Dec 2, 2023
1 parent 972b3ef commit 843c415
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 70 deletions.
3 changes: 0 additions & 3 deletions R/add_padding.R
Expand Up @@ -79,8 +79,6 @@ trim_padding = function(heightmap, pad = 1) {
#'
#'@description Pads to a rect
#'
#'@param heightmap A two-dimensional matrix, where each entry in the matrix is the elevation at that point. All points are assumed to be evenly spaced.
#'@param pad Number of padding entries
#'@return Hillshade with edges trimmed
#'@keywords internal
pad_to_fit = function(dim, kernel) {
Expand Down Expand Up @@ -115,7 +113,6 @@ pad_to_fit = function(dim, kernel) {
#'
#'@description Pads to a rect
#'
#'@param dim desired size
#'@return Hillshade with edges trimmed
#'@keywords internal
expand_to_fit = function(dim, kernel) {
Expand Down
2 changes: 0 additions & 2 deletions R/convert_to_native_raster.R
Expand Up @@ -3,8 +3,6 @@
#'@description Displays the image in the current device.
#'
#'@param input Array to get converted to a native raster
#'@param ncol Number of columns
#'@param nrow Number of rows
#'@keywords internal
convert_to_native_raster = function(input) {
ncol = ncol(input)
Expand Down
4 changes: 0 additions & 4 deletions man/convert_to_native_raster.Rd

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

3 changes: 0 additions & 3 deletions man/expand_to_fit.Rd

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

5 changes: 0 additions & 5 deletions man/pad_to_fit.Rd

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

108 changes: 55 additions & 53 deletions tests/testthat/test-plot_image.R
@@ -1,53 +1,55 @@
# 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())
# })
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", {
skip_on_os(c("windows", "linux", "solaris"))
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", {
skip_on_os(c("windows", "linux", "solaris"))
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 843c415

Please sign in to comment.