Skip to content

Commit 6d9272d

Browse files
Add tests for sigmas input
1 parent 1951488 commit 6d9272d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

tests/testthat/test-ccdr_singleR.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,28 @@ test_that("Check input: betas", {
150150
expect_true(is.zero(final$sbm))
151151
})
152152

153+
test_that("Check input: sigmas", {
154+
### sigmas is numeric
155+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, sigmas = rep("a", pp), lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test),
156+
"sigmas must be numeric")
157+
158+
### sigmas has correct length
159+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, sigmas = rep(1, pp+1), lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test),
160+
"sigmas must have length")
161+
162+
### Negative values other than 1 fail
163+
sigmas1 <- sigmas.test
164+
sigmas1[1] <- -2
165+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, sigmas = sigmas1, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test),
166+
"sigmas must be > 0!")
167+
168+
### Combination of +/- values fails
169+
sigmas1 <- runif(pp)
170+
sigmas1[1] <- -1
171+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, sigmas = sigmas1, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test),
172+
"sigmas must be > 0!")
173+
})
174+
153175
test_that("Check input: lambda", {
154176

155177
### lambda is numeric

tests/testthat/test-sigmas.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
context("sigmas")
2+
3+
dat <- generate_fixed_data_frame()
4+
sbdata <- suppressMessages(sparsebnData(dat, type = "c"))
5+
pp <- ncol(dat)
6+
7+
test_that("Output is the same when sigmas is specified manually", {
8+
dags.null <- ccdr.run(sbdata, lambdas.length = 20)
9+
dags.null <- lapply(dags.null, function(x) x$edges)
10+
11+
dags.sigmas <- ccdr.run(sbdata, lambdas.length = 20, sigmas = rep(-1, ncol(dat)))
12+
dags.sigmas <- lapply(dags.sigmas, function(x) x$edges)
13+
14+
expect_equal(dags.null, dags.sigmas)
15+
})
16+
17+
test_that("Setting sigmas works without error", {
18+
### LS loss
19+
expect_error(ccdr.run(sbdata, lambdas.length = 20, sigmas = rep(1, ncol(dat))),
20+
NA)
21+
22+
### Arbitrary positive values
23+
expect_error(ccdr.run(sbdata, lambdas.length = 20, sigmas = runif(pp)),
24+
NA)
25+
})

0 commit comments

Comments
 (0)