Nothing
outline <- terra::vect(system.file("extdata", "example_outline.shp", package = "rLakeHabitat"))
dat <- read.csv(system.file("extdata", "example_depths.csv", package = "rLakeHabitat"))
# input validation
test_that("optimizeParams errors on non-dataframe df", {
expect_error(
optimizeParams(outline, df = as.matrix(dat), "x", "y", "z", spacings = c(10, 20), res_values = c(5, 10)),
"df must be a dataframe"
)
})
test_that("optimizeParams errors on invalid spacings", {
expect_error(
optimizeParams(outline, dat, "x", "y", "z", spacings = c(-5, 10), res_values = c(5, 10)),
"spacings must be positive numeric values"
)
expect_error(
optimizeParams(outline, dat, "x", "y", "z", spacings = "ten", res_values = c(5, 10)),
"spacings must be positive numeric values"
)
})
test_that("optimizeParams errors on invalid res_values", {
expect_error(
optimizeParams(outline, dat, "x", "y", "z", spacings = c(10, 20), res_values = c(0, -5)),
"res_values must be positive numeric values"
)
})
test_that("optimizeParams errors on invalid method", {
expect_error(
optimizeParams(outline, dat, "x", "y", "z", spacings = c(10, 20), res_values = c(5, 10), method = "krige"),
"method misspecified"
)
})
test_that("optimizeParams errors on invalid tolerance", {
expect_error(
optimizeParams(outline, dat, "x", "y", "z", spacings = c(10, 20), res_values = c(5, 10), tolerance = -1),
"tolerance must be a non-negative numeric value"
)
})
test_that("optimizeParams errors on invalid seed", {
expect_error(
optimizeParams(outline, dat, "x", "y", "z", spacings = c(10, 20), res_values = c(5, 10), seed = "abc"),
"seed must be numeric"
)
})
test_that("optimizeParams returns expected structure on a small grid", {
result <- optimizeParams(outline, dat, "x", "y", "z", spacings = c(20, 50), res_values = c(10, 20),
k = 3, zeros = FALSE, separation = 10, nmax = 4, plot = FALSE, seed = 123)
expect_type(result, "list")
expect_named(result, c("results", "recommended_spacing", "recommended_res"))
expect_s3_class(result$results, "data.frame")
expect_named(result$results, c("spacing", "res", "mean_rmse", "n_points"))
expect_equal(nrow(result$results), 4)
expect_true(result$recommended_spacing %in% c(20, 50))
expect_true(result$recommended_res %in% c(10, 20))
expect_true(all(result$results$n_points > 0, na.rm = TRUE))
})
test_that("optimizeParams de-duplicates and sorts spacings/res_values", {
result <- optimizeParams(outline, dat, "x", "y", "z", spacings = c(50, 20, 20), res_values = c(20, 10),
k = 3, zeros = FALSE, separation = 10, nmax = 4, plot = FALSE, seed = 123)
expect_equal(nrow(result$results), 4)
expect_equal(sort(unique(result$results$spacing)), c(20, 50))
})
test_that("optimizeParams is reproducible with a fixed seed", {
r1 <- optimizeParams(outline, dat, "x", "y", "z", spacings = c(20, 50), res_values = c(10, 20),
k = 3, zeros = FALSE, separation = 10, nmax = 4, plot = FALSE, seed = 99)
r2 <- optimizeParams(outline, dat, "x", "y", "z", spacings = c(20, 50), res_values = c(10, 20),
k = 3, zeros = FALSE, separation = 10, nmax = 4, plot = FALSE, seed = 99)
expect_equal(r1$results$mean_rmse, r2$results$mean_rmse)
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.