Skip to content

Commit

Permalink
unit tewsts for sw_interval, sw_sum, sw_sum_plot
Browse files Browse the repository at this point in the history
  • Loading branch information
hanecakr committed Nov 20, 2023
1 parent 6b0275f commit 79774b1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .Rproj.user/429CC01A/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"activeTab": 20,
"activeTab": 21,
"activeTabSourceWindow0": 0
}
23 changes: 13 additions & 10 deletions tests/testthat/test-sw_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ testthat::test_that("sw_data exists", {
)
})

# testthat::test_that("hdi with very large n_sapwood gives warning", {
# testthat::expect_warning(
# sw_interval(
# n_sapwood = 12345,
# last = 1234,
# hdi = TRUE,
# ),
# regexp = "n_sapwood"
# )
# })

testthat::test_that("hdi works with lognormal density function", {
hdi <- sw_interval(
Expand Down Expand Up @@ -110,3 +100,16 @@ testthat::test_that("d.dens does not work with invalid density function", {
regexp = "not a supported distribution"
)
})

testthat::test_that("output is list", {
x <- sw_interval(
n_sapwood = 10,
last = 1234,
hdi = TRUE,
credMass = .95,
sw_data = "Wazny_1990",
densfun = "normal"
)
testthat::expect_type(x, "list")
testthat::expect_equal(length(x), 3)
})
25 changes: 25 additions & 0 deletions tests/testthat/test-sw_sum.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,28 @@ testthat::test_that("Output is a data.frame", {
testthat::expect_s3_class(x, "data.frame")
testthat::expect_true('SPD' %in% names(x))
})

testthat::test_that("Output is a data.frame", {
x <- sw_sum(fellingdateR:::dummy6, plot = FALSE)
testthat::expect_s3_class(x, "data.frame")
testthat::expect_true('SPD' %in% names(x))
})

testthat::test_that("sw_sum does not work with invalid density function", {
testthat::expect_error(
sw_sum(
fellingdateR:::dummy7,
densfun = "nuka-cola"
),
regexp = "not a supported distribution"
)
})

testthat::test_that("sw_sum does not work with invalid credMass", {
testthat::expect_error(
sw_sum(
fellingdateR:::dummy7,
credMass = "ninety percent"
)
)
})
2 changes: 2 additions & 0 deletions tests/testthat/test-sw_sum_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ testthat::test_that("sw_sum_plot() returns a ggplot object", {
x <- sw_sum_plot(x)
testthat::expect_true("ggproto" %in% class(x$layers[[1]]$stat))
})


0 comments on commit 79774b1

Please sign in to comment.