Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Sep 16, 2024
1 parent 8be0d60 commit 2238978
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
12 changes: 6 additions & 6 deletions tests/testthat/test-apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@ test_that("Recycling rules and output for applying multiple inputs over multiple
dimnames(dist_named) <- c("a", "b")

expect_equal(
quantile(dist, 0.5),
quantile(dist, 0.5, type = "marginal"),
matrix(c(1,3,2,5), nrow = 2)
)
expect_equal(
quantile(dist_named, 0.5),
quantile(dist_named, 0.5, type = "marginal"),
matrix(c(1,3,2,5), nrow = 2, dimnames = list(NULL, c("a", "b")))
)

expect_equal(
quantile(dist, c(0.5, 0.9)),
quantile(dist, c(0.5, 0.9), type = "marginal"),
list(matrix(c(1, 3.5631031310892, 2, 4.21971242404268), ncol = 2),
matrix(c(3, 5.86563641722901, 5, 7.5631031310892), ncol = 2))
)
expect_equal(
quantile(dist_named, c(0.5, 0.9)),
quantile(dist_named, c(0.5, 0.9), type = "marginal"),
list(matrix(c(1, 3.5631031310892, 2, 4.21971242404268), ncol = 2, dimnames = list(NULL, c("a", "b"))),
matrix(c(3, 5.86563641722901, 5, 7.5631031310892), ncol = 2, dimnames = list(NULL, c("a", "b"))))
)

expect_equal(
quantile(dist, c(0.5, 0.9, 0.95)),
quantile(dist, c(0.5, 0.9, 0.95), type = "marginal"),
list(
matrix(c(1, 3.5631031310892, 4.28970725390294, 2, 4.21971242404268, 4.84897005289389),
ncol = 2),
Expand All @@ -113,7 +113,7 @@ test_that("Recycling rules and output for applying multiple inputs over multiple
)
)
expect_equal(
quantile(dist_named, c(0.5, 0.9, 0.95)),
quantile(dist_named, c(0.5, 0.9, 0.95), type = "marginal"),
list(
matrix(c(1, 3.5631031310892, 4.28970725390294, 2, 4.21971242404268, 4.84897005289389),
ncol = 2, dimnames = list(NULL, c("a","b"))),
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-dist-gh.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test_that("g-and-h distribution", {
expect_equal(format(dist), "gh(A = 0, B = 1, g = 0, h = 0.5)")

# Require package installed
skip_if_not_installed("gh", "0.1.0")
skip_if_not_installed("gk", "0.1.0")

# quantiles
expect_equal(quantile(dist, 0.1), gk::qgh(0.1, A, B, g, h, c))
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-dist-multivariate-normal.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ test_that("Multivariate normal distribution", {

# quantiles
expect_equal(
quantile(dist, 0.1),
quantile(dist, 0.1, type = "marginal"),
matrix(c(qnorm(0.1, mu[1], sqrt(sigma[1,1])), qnorm(0.1, mu[2], sqrt(sigma[2,2]))),
nrow = 1, dimnames = list(NULL, c("a", "b")))
)

skip_if_not_installed("mvtnorm")
expect_equivalent(quantile(dist, 0.1, type = "equicoordinate"), mvtnorm::qmvnorm(0.1, mean = mu, sigma = sigma)$quantile)
expect_equivalent(
quantile(dist, 0.1, type = "equicoordinate"),
rep(mvtnorm::qmvnorm(0.1, mean = mu, sigma = sigma)$quantile, 2)
)

# pdf
expect_equal(density(dist, cbind(1, 2)), mvtnorm::dmvnorm(c(1, 2), mean = mu, sigma = sigma))
expect_equal(density(dist, cbind(-3, 4)), mvtnorm::dmvnorm(c(-3, 4), mean = mu, sigma = sigma))

# cdf
expect_equivalent(cdf(dist, cbind(1, 2)), mvtnorm::pmvnorm(upper = c(1,2), mean = mu, sigma = sigma))
expect_equivalent(cdf(dist, cbind(-3, 4)), mvtnorm::pmvnorm(c(-3, 4), mean = mu, sigma = sigma))
expect_equivalent(cdf(dist, cbind(-3, 4)), mvtnorm::pmvnorm(upper = c(-3, 4), mean = mu, sigma = sigma))

# F(Finv(a)) ~= a
# expect_equal(cdf(dist, list(as.numeric(quantile(dist, 0.53)))), 0.53, tolerance = 1e-3)
Expand Down

0 comments on commit 2238978

Please sign in to comment.