Skip to content

Commit

Permalink
Add some tests for dqrmvnorm.
Browse files Browse the repository at this point in the history
  • Loading branch information
rstub committed Aug 15, 2023
1 parent 90d0d55 commit 4a2c7f8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/testthat/test-rmv.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
context("multivariate generators")

seed <- 1234567890
sigma <- matrix(c(4,2,2,3), ncol=2)
mean <- c(1,2)

test_that("consecutive calls yield different random numbers (normal)", {
skip_if_not_installed("mvtnorm")
dqset.seed(seed)
n1 <- dqrmvnorm(10, mean = mean, sigma=sigma)
n2 <- dqrmvnorm(10, mean = mean, sigma=sigma)
expect_false(all(n1 == n2))
})

test_that("setting seed produces identical normaly distributed numbers", {
dqset.seed(seed)
n1 <- dqrmvnorm(10, mean = mean, sigma=sigma)
dqset.seed(seed)
n2 <- dqrmvnorm(10, mean = mean, sigma=sigma)
expect_equal(n1, n2)
})

test_that("Means and variance as expected",{
dqset.seed(seed)
n1 <- dqrmvnorm(1e5, mean = mean, sigma=sigma)
expect_equal(mean, colMeans(n1), tolerance = 0.01)
expect_equal(sigma, var(n1), tolerance = 0.01)
})
#

0 comments on commit 4a2c7f8

Please sign in to comment.