Skip to content

Commit

Permalink
add tangent testing gap
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Oct 8, 2024
1 parent 8236f57 commit 95073b5
Showing 1 changed file with 56 additions and 16 deletions.
72 changes: 56 additions & 16 deletions tests/testthat/test-fitdistdoublecens.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,59 @@ test_that("fitdistdoublecens works with mixed secondary windows", {
expect_equal(unname(fit_gamma$estimate["rate"]), true_rate, tolerance = 0.2)
})

test_that("fitdistdoublecens throws error when fitdistrplus is not installed", {
with_mocked_bindings(
{
# Create dummy data
dummy_data <- data.frame(left = 1:5, right = 2:6)

# Expect an error when trying to use fitdistdoublecens
expect_error(
fitdistdoublecens(dummy_data, "norm"),
"Package 'fitdistrplus' is required but not installed for this"
)
},
requireNamespace = function(...) FALSE,
.package = "base"
)
})
test_that(
"fitdistdoublecens throws error when required packages are not installed",
{
# Create dummy data
dummy_data <- data.frame(left = 1:5, right = 2:6)

# Test for fitdistrplus
with_mocked_bindings(
{
expect_error(
fitdistdoublecens(dummy_data, "norm"),
"Package 'fitdistrplus' is required but not installed for this",
fixed = TRUE
)
},
requireNamespace = function(pkg, ...) {
if (pkg == "fitdistrplus") {
return(FALSE)
}
TRUE
},
.package = "base"
)

# Test for withr
with_mocked_bindings(
{
expect_error(
fitdistdoublecens(dummy_data, "norm"),
"Package 'withr' is required but not installed for this function.",
fixed = TRUE
)
},
requireNamespace = function(pkg, ...) {
if (pkg == "withr") {
return(FALSE)
}
TRUE
},
.package = "base"
)

# Test when both packages are missing
with_mocked_bindings(
{
expect_error(
fitdistdoublecens(dummy_data, "norm"),
"Package 'fitdistrplus' is required but not installed",
fixed = TRUE
)
},
requireNamespace = function(...) FALSE,
.package = "base"
)
}
)

0 comments on commit 95073b5

Please sign in to comment.