diff --git a/tests/testthat/_snaps/setResource.md b/tests/testthat/_snaps/setResource.md new file mode 100644 index 000000000..eb16c94a3 --- /dev/null +++ b/tests/testthat/_snaps/setResource.md @@ -0,0 +1,9 @@ +# We can set and get resource parameters + + Code + params <- setResource(params, r_pp = r_pp, kappa = kappa, lambda = lambda, n = n, + w_pp_cutoff = w_pp_cutoff) + Message + The resource intrinsic growth rate has been commented and therefore will not be recalculated from the resource parameters. + The resource carrying capacity has been commented and therefore will not be recalculated from the resource parameters. + diff --git a/tests/testthat/_snaps/steady.md b/tests/testthat/_snaps/steady.md new file mode 100644 index 000000000..7009ced84 --- /dev/null +++ b/tests/testthat/_snaps/steady.md @@ -0,0 +1,10 @@ +# steady works + + c("1" = 1.12523946834203, "2" = 0.378015488322643, "3" = 0.124113033074317, + "4" = 0.0412195840646914) + +--- + + c("1" = 1.12523946834203, "2" = 0.378015488322643, "3" = 0.124113033074317, + "4" = 0.0412195840646914) + diff --git a/tests/testthat/test-animateSpectra.R b/tests/testthat/test-animateSpectra.R index ba210ce63..7e8376a16 100644 --- a/tests/testthat/test-animateSpectra.R +++ b/tests/testthat/test-animateSpectra.R @@ -1,3 +1,4 @@ +local_edition(3) test_that("animateSpectra does not throw error", { sim <- project(NS_params, t_max = 2, t_save = 1, effort = 1) expect_error(animateSpectra(sim, species = c("Cod", "Haddock"), diff --git a/tests/testthat/test-calibrate.R b/tests/testthat/test-calibrate.R index 9660653ba..51ed5cccf 100644 --- a/tests/testthat/test-calibrate.R +++ b/tests/testthat/test-calibrate.R @@ -1,3 +1,4 @@ +local_edition(3) # calibrateBiomass ---- test_that("calibrateBiomass works", { params <- NS_params diff --git a/tests/testthat/test-compareParams.R b/tests/testthat/test-compareParams.R index 69a86c387..1dab8120c 100644 --- a/tests/testthat/test-compareParams.R +++ b/tests/testthat/test-compareParams.R @@ -1,3 +1,5 @@ +local_edition(3) + test_that("compareParams", { local_reproducible_output() params <- NS_params diff --git a/tests/testthat/test-setResource.R b/tests/testthat/test-setResource.R index 7b28a0605..e8a047478 100644 --- a/tests/testthat/test-setResource.R +++ b/tests/testthat/test-setResource.R @@ -1,3 +1,4 @@ +local_edition(3) test_that("We can set and get resource parameters", { params <- NS_params rp <- resource_params(params) @@ -39,10 +40,9 @@ test_that("We can set and get resource parameters", { expect_identical(getResourceRate(params), resource_rate) expect_identical(getResourceCapacity(params), resource_capacity) # Check that comments protect - expect_message(params <- setResource(params, r_pp = r_pp, kappa = kappa, + expect_snapshot(params <- setResource(params, r_pp = r_pp, kappa = kappa, lambda = lambda, n = n, - w_pp_cutoff = w_pp_cutoff), - "The resource carrying capacity has been commented") + w_pp_cutoff = w_pp_cutoff)) comment(params@cc_pp) <- NULL expect_message(params <- setResource(params, r_pp = r_pp, kappa = kappa, lambda = lambda, n = n, @@ -56,8 +56,8 @@ test_that("We can set and get resource parameters", { r_pp * params@w_full^(n - 1)) resource_capacity <- getResourceCapacity(params) cc_pp <- kappa*params@w_full^(-lambda) - expect_equivalent(cc_pp[params@w_full <= w_pp_cutoff], - resource_capacity[params@w_full <= w_pp_cutoff]) + expect_equal(cc_pp[params@w_full <= w_pp_cutoff], + unname(resource_capacity[params@w_full <= w_pp_cutoff])) # resource_params<- sets rates correctly resource_params(NS_params) <- resource_params(params) expect_unchanged(NS_params, params) @@ -89,7 +89,7 @@ test_that("Comment works on resource_rate", { p <- setResource(params, reset = TRUE) expect_equal(p@rr_pp[1], params@w_full[1] ^ (params@resource_params$n - 1), - check.attributes = FALSE) + ignore_attr = TRUE) expect_warning(setResource(params, resource_rate = resource_rate, reset = TRUE), "Because you set `reset = TRUE`, the") @@ -121,7 +121,7 @@ test_that("Comment works on resource_capacity", { p <- setResource(params, reset = TRUE) expect_equal(p@cc_pp[1], params@w_full[1] ^ (-params@resource_params$lambda), - check.attributes = FALSE) + ignore_attr = TRUE) expect_warning(setResource(params, resource_capacity = resource_capacity, reset = TRUE), "Because you set `reset = TRUE`, the") diff --git a/tests/testthat/test-steady.R b/tests/testthat/test-steady.R index b4b59e365..5fda8c892 100644 --- a/tests/testthat/test-steady.R +++ b/tests/testthat/test-steady.R @@ -1,3 +1,4 @@ +local_edition(3) # projectToSteady ---- test_that("projectToSteady() works", { params <- NS_params @@ -35,7 +36,7 @@ test_that("projectToSteady() works", { # Check extinction params@psi[5:6, ] <- 0 - expect_warning(projectToSteady(params), + expect_warning(projectToSteady(params) |> suppressMessages(), "Dab, Whiting are going extinct.") }) @@ -49,36 +50,41 @@ test_that("steady works", { "Increased no_w to 36") params@species_params$gamma[2] <- 2000 params <- setSearchVolume(params) - p <- steady(params, t_per = 2) - expect_known_value(getRDD(p), "values/steady") + p <- steady(params, t_per = 2) |> + suppressMessages() + expect_snapshot_value(getRDD(p), style = "deparse") # and works the same when returning sim - sim <- steady(params, t_per = 2, return_sim = TRUE) - expect_is(sim, "MizerSim") - expect_known_value(getRDD(sim@params), "values/steady") + sim <- steady(params, t_per = 2, return_sim = TRUE) |> + suppressMessages() + expect_s4_class(sim, "MizerSim") + expect_snapshot_value(getRDD(sim@params), style = "deparse") }) -test_that("steady() preserves erepro", { +test_that("steady() preserves reproduction function", { params <- NS_params params@rates_funcs$RDD <- "noRDD" - p2 <- steady(params, t_per = 1) + p2 <- steady(params, t_per = 1, t_max = 1) |> suppressMessages() expect_equal(params@rates_funcs$RDD, "noRDD") }) test_that("steady() preserves erepro", { params <- NS_params species_params(params)$R_max <- 1.01 * species_params(params)$R_max - p2 <- steady(params, t_per = 1, preserve = "erepro") + p2 <- steady(params, t_per = 1, preserve = "erepro") |> + suppressMessages() expect_equal(p2@species_params$erepro, params@species_params$erepro) }) test_that("steady() preserves reproduction level", { params <- NS_params species_params(params)$R_max <- 1.01 * species_params(params)$R_max - p2 <- steady(params, t_per = 1, preserve = "reproduction_level") + p2 <- steady(params, t_per = 1, preserve = "reproduction_level") |> + suppressMessages() expect_equal(getReproductionLevel(p2), getReproductionLevel(params)) }) test_that("steady() preserves R_max", { params <- NS_params species_params(params)$erepro <- 1.01 * species_params(params)$erepro - expect_warning(p2 <- steady(params, t_per = 1, preserve = "R_max"), + expect_warning(p2 <- steady(params, t_per = 1, preserve = "R_max") |> + suppressMessages(), "The following species require an unrealistic reproductive") expect_equal(p2@species_params$R_max, params@species_params$R_max) })