Skip to content

Commit

Permalink
dont run ssd_exposure example but do tests (with with_seed)
Browse files Browse the repository at this point in the history
  • Loading branch information
joethorley committed Oct 9, 2024
1 parent 514eda5 commit 3a9b015
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
14 changes: 8 additions & 6 deletions R/exposure.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Energy, the Environment and Water
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compl %>% iance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -26,11 +26,13 @@
#' @return The proportion exposed.
#' @export
#' @examples
#' fits <- ssd_fit_dists(ssddata::ccme_boron, dists = "lnorm")
#' set.seed(10)
#' ssd_exposure(fits)
#' ssd_exposure(fits, meanlog = 1)
#' ssd_exposure(fits, meanlog = 1, sdlog = 1)
#' \dontrun{
#' fits <- ssd_fit_dists(ssddata::ccme_boron, dists = "lnorm")
#' set.seed(10)
#' ssd_exposure(fits)
#' ssd_exposure(fits, meanlog = 1)
#' ssd_exposure(fits, meanlog = 1, sdlog = 1)
#' }
ssd_exposure <- function(x, meanlog = 0, sdlog = 1, nboot = 1000) {
chk_number(meanlog)
chk_number(sdlog)
Expand Down
12 changes: 7 additions & 5 deletions man/ssd_exposure.Rd

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

40 changes: 17 additions & 23 deletions tests/testthat/test-exposure.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,41 @@
# limitations under the License.

test_that("exposure fitdist", {
skip_on_cran() # slow on debian
fits <- ssd_fit_dists(ssddata::ccme_boron, dists = "lnorm")

set.seed(1)
expect_equal(ssd_exposure(fits), 0.0554387492913971, tolerance = 1e-5)
withr::with_seed(1, {
expect_equal(ssd_exposure(fits), 0.0554388713536206, tolerance = 1e-6)
})
})

test_that("exposure different mean", {
skip_on_cran() # slow on debian
fits <- ssd_fit_dists(ssddata::ccme_boron, dists = "lnorm")

set.seed(1)
expect_equal(ssd_exposure(fits, 1), 0.165064432413281, tolerance = 1e-6)
withr::with_seed(1, {
expect_equal(ssd_exposure(fits, 1, nboot = 100), 0.170901838844338, tolerance = 1e-6)
})
})

test_that("exposure different mean and log", {
skip_on_cran() # slow on debian
fits <- ssd_fit_dists(ssddata::ccme_boron, dists = "lnorm")

set.seed(1)
expect_equal(ssd_exposure(fits, 1, sdlog = 10), 0.433888512432359, tolerance = 1e-7)
withr::with_seed(1, {
expect_equal(ssd_exposure(fits, 1, sdlog = 10, nboot = 100), 0.490815139369754, tolerance = 1e-6)
})
})

test_that("exposure multiple distributions", {
skip_on_cran() # slow on debian
fits <- ssd_fit_dists(ssddata::ccme_boron)

set.seed(1)
expect_equal(ssd_exposure(fits), 0.0663588247125051, tolerance = 1e-5)
withr::with_seed(1, {
expect_equal(ssd_exposure(fits, nboot = 100), 0.0663472624824284, tolerance = 1e-6)
})
})

test_that("exposure somewhat sensitive to rescaling", {
skip_on_cran() # slow on debian
fits <- ssd_fit_dists(ssddata::ccme_boron, dists = "lnorm")

set.seed(10)
exposure <- ssd_exposure(fits)

fits_rescale <- ssd_fit_dists(ssddata::ccme_boron, dists = "lnorm", rescale = TRUE)
set.seed(10)
exposure_rescale <- ssd_exposure(fits_rescale)
test_that("exposure fitdist rescale", {
fits <- ssd_fit_dists(ssddata::ccme_boron, dists = "lnorm", rescale = TRUE)

expect_equal(exposure_rescale, exposure, tolerance = 1e-3)
withr::with_seed(1, {
expect_equal(ssd_exposure(fits), 0.0554388582680626, tolerance = 1e-6)
})
})

0 comments on commit 3a9b015

Please sign in to comment.