Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip other tests that rely on the sn package if it is not installed. #74

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/testthat/test-dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ test_that("student deviance", {
})

test_that("skewnorm missing values", {
skip_if_not_installed("sn")
expect_identical(dev_skewnorm(logical(0), integer(0), numeric(0), numeric(0)), numeric(0))
expect_identical(dev_skewnorm(NA, 1, 1, 1), NA_real_)
expect_identical(dev_skewnorm(1, NA, 1, 1), NA_real_)
Expand All @@ -775,6 +776,7 @@ test_that("skewnorm missing values", {
})

test_that("skewnorm known values", {
skip_if_not_installed("sn")
expect_identical(dev_skewnorm(1, 1), 0)
expect_identical(dev_skewnorm(1, 1, 1), 0)
expect_equal(dev_skewnorm(1, 1, 1, 1), 0.398456311678723)
Expand All @@ -800,13 +802,15 @@ test_that("skewnorm known values", {
})

test_that("skewnorm vectorized", {
skip_if_not_installed("sn")
expect_equal(dev_skewnorm(0:3, 2, 0.1, 0), c(400, 100, 0, 100))
expect_equal(dev_skewnorm(c(0, 1, 3, 0), 3, 0.5, 0.5), c(47.9668417319782, 22.3177579563216, 0.137683650077409, 47.9668417319782))
expect_equal(dev_skewnorm(0:3, 0:3, rep(1, 4), 0), rep(0, 4))
expect_equal(dev_skewnorm(0:3, 3:0, 0:3, seq(0, 1, length.out = 4)), c(Inf, 1.67133656780082, 0.00816257443560442, 0.357669508605733))
})

test_that("skewnorm vectorized missing values", {
skip_if_not_installed("sn")
expect_equal(dev_skewnorm(c(NA, 1), 0:1, 0:1, 0:1), c(NA, 0.398456311678723))
expect_equal(dev_skewnorm(c(0, NA), 0:1, 1:2, 0:1), c(0, NA))
expect_equal(dev_skewnorm(c(0:1), c(NA, 1), 1:2, 0:1), c(NA, 0.398456311678724))
Expand All @@ -818,18 +822,21 @@ test_that("skewnorm vectorized missing values", {
})

test_that("skewnorm res", {
skip_if_not_installed("sn")
expect_equal(dev_skewnorm(10, 0.5, 0.5), dev_skewnorm(10, 0.5, 0.5, res = TRUE)^2)
expect_equal(dev_skewnorm(0:1, c(0.3, 0.6), 0.5), dev_skewnorm(0:1, c(0.3, 0.6), 0.5, res = TRUE)^2)
})

test_that("skewnorm log_lik", {
skip_if_not_installed("sn")
expect_equal(
dev_skewnorm(0:1, 1:2, 2:3, shape = 0),
2 * (log_lik_skewnorm(0:1, 0:1, 2:3, shape = 0) - log_lik_skewnorm(0:1, 1:2, 2:3, shape = 0))
)
})

test_that("skewnorm ran", {
skip_if_not_installed("sn")
set.seed(101)
samples <- ran_skewnorm(100000, 3, 0.5, 0.5)
expect_equal(mean(samples), 3.17851201086154)
Expand All @@ -840,6 +847,7 @@ test_that("skewnorm ran", {
})

test_that("skewnorm deviance", {
skip_if_not_installed("sn")
samples <- ran_skewnorm(1000, 3, 0.5, 0)
mod <- glm(samples ~ 1, family = gaussian)
deviance <- sum(dev_skewnorm(samples, coef(mod)[1]))
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-log-lik.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ test_that("beta_binom log_lik", {
})

test_that("skewnorm missing values", {
skip_if_not_installed("sn")
expect_identical(log_lik_skewnorm(numeric(0), numeric(0), numeric(0), numeric(0)), numeric(0))
expect_identical(log_lik_skewnorm(1, numeric(0)), numeric(0))
expect_identical(log_lik_skewnorm(1, 1, sd = numeric(0)), numeric(0))
Expand All @@ -204,6 +205,7 @@ test_that("skewnorm missing values", {
})

test_that("skewnorm known values", {
skip_if_not_installed("sn")
expect_equal(log_lik_skewnorm(0.5, 3), -4.04393853320467)
expect_equal(log_lik_skewnorm(0.5, 3, 0), -Inf)
expect_equal(log_lik_skewnorm(0.5, 3, 1, -4), -3.35079135264473)
Expand All @@ -220,6 +222,7 @@ test_that("skewnorm known values", {
})

test_that("skewnorm vectorized", {
skip_if_not_installed("sn")
expect_equal(
log_lik_skewnorm(0:3, 2, 0.5, 0),
c(-8.22579135264473, -2.22579135264473, -0.225791352644727, -2.22579135264473)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-ran.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ test_that("ran_beta_binom", {
})

test_that("ran_skewnorm", {
skip_if_not_installed("sn")
expect_error(ran_skewnorm(NA_integer_))
expect_error(ran_skewnorm(NULL))
expect_error(ran_skewnorm(integer(0)))
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-res.R
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ test_that("res_beta_binom", {
})

test_that("res_skewnorm", {
skip_if_not_installed("sn")
expect_identical(res_skewnorm(integer(0), integer(0), integer(0)), numeric(0))
expect_identical(res_skewnorm(NA, 1, 1, 1), NA_real_)
expect_identical(res_skewnorm(1, NA, 1, 1), NA_real_)
Expand Down
Loading