Skip to content

Commit 418f6cc

Browse files
Fix broken unit tests caused by missing weights argument
1 parent b67229a commit 418f6cc

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

R/ccdrAlgorithm-main.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ ccdr_call <- function(data,
126126
betas,
127127
lambdas,
128128
lambdas.length,
129-
whitelist,
130-
blacklist,
129+
whitelist = NULL,
130+
blacklist = NULL,
131131
gamma,
132132
error.tol,
133133
rlam,

tests/testthat/test-ccdr_gridR.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ indexj.test <- rep(0L, pp + 1)
99
nj.test <- as.integer(rep(nn, pp))
1010
cors.length <- pp*(pp+1)/2
1111
lambda.test <- pi
12+
weights.test <- rep(1, pp*pp)
1213
gamma.test <- 2.0
1314
eps.test <- 0.1
1415
maxIters.test <- 1000L
@@ -28,5 +29,5 @@ alpha.test <- 10
2829
# verbose)
2930

3031
test_that("ccdr_gridR runs as expected", {
31-
expect_error(ccdr_gridR(cors = as.numeric(cors.test), pp = pp, nn = nn, betas = betas.test, lambdas = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test, verbose = FALSE), NA)
32+
expect_error(ccdr_gridR(cors = as.numeric(cors.test), pp = pp, nn = nn, betas = betas.test, lambdas = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test, verbose = FALSE), NA)
3233
})

tests/testthat/test-ccdr_singleR.R

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cors.length <- pp*(pp+1)/2
88
cors.test <- runif(cors.length)
99
betas.test <- matrix(runif(pp*pp), ncol = pp)
1010
lambda.test <- pi
11+
weights.test <- rep(1, pp*pp)
1112
gamma.test <- 2.0
1213
eps.test <- 0.1
1314
maxIters.test <- 1000L
@@ -29,128 +30,142 @@ test_that("ccdr_singleR runs as expected", {
2930
expect_error(ccdr_singleR(cors = cors.test))
3031

3132
### No error
32-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test), NA)
33+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test), NA)
3334

3435
### No error
35-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj, indexj = indexj, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test), NA)
36+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj, indexj = indexj, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test), NA)
3637

3738
})
3839

3940
test_that("Check input: cors", {
4041

4142
### Throw error if cors has length != pp*(pp+1)/2
42-
expect_error(ccdr_singleR(cors = cors.test[-1], pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
43+
expect_error(ccdr_singleR(cors = cors.test[-1], pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
4344
})
4445

4546
test_that("Check input: pp", {
4647

4748
### pp is not an integer
48-
expect_error(ccdr_singleR(cors = cors.test, pp = pi, nn = nn, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
49+
expect_error(ccdr_singleR(cors = cors.test, pp = pi, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
4950

5051
### pp is not > 0
51-
expect_error(ccdr_singleR(cors = cors.test, pp = -1L, nn = nn, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
52+
expect_error(ccdr_singleR(cors = cors.test, pp = -1L, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
5253
})
5354

5455
test_that("Check input: nn", {
5556

5657
### nn is not an integer
57-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = pi, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
58+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = pi, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
5859

5960
### nn is not > 0
60-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = -1L, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
61+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = -1L, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
6162
})
6263

6364
test_that("Check input: indexj", {
6465
### indexj is defined to be a vector containing the start position of the correlation matrix for node j in 'cors'
6566

6667
### indexj is not a vector
67-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = matrix(0L, nrow = 1, ncol = pp + 1), betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
68+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = matrix(0L, nrow = 1, ncol = pp + 1), betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
6869

6970
### indexj is of wrong size
70-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = rep(0L, pp + 2), betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
71+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = rep(0L, pp + 2), betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
7172

7273
### indexj has non-integer
7374
indexj1 <- indexj
7475

7576
indexj1[1] <- pi
76-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = indexj1, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
77+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = indexj1, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
7778

7879
indexj1[1] <- NA
79-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = indexj1, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
80+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = indexj1, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
8081

8182
### indexj out of bound
8283
indexj1[1] <- 0
83-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = indexj1, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
84+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = indexj1, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
8485

8586
indexj1[1] <- pp + 2
86-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = indexj1, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
87+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, indexj = indexj1, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
8788
})
8889

8990
test_that("Check input: nj", {
9091
### nj is defined to be a vector containing the number of times each node is free of intervention (to replace nn)
9192

9293
### nj is not a vector
93-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = matrix(nn, nrow = 1, ncol = pp), betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
94+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = matrix(nn, nrow = 1, ncol = pp), betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
9495

9596
### nj is of wrong size
96-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = as.integer(rep(nn, pp + 1)), betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
97+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = as.integer(rep(nn, pp + 1)), betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
9798

9899
### nj has non-integer
99100
nj1 <- nj
100101

101102
nj1[1] <- pi
102-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj1, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
103+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj1, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
103104

104105
nj1[1] <- NA
105-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj1, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
106+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj1, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
106107

107108
### nj out of bound
108109
nj1 <- rep(-1L, pp)
109-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj1, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
110+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj1, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
110111

111112
nj1 <- as.integer(rep(nn + 1, pp))
112-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj1, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
113+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, nj = nj1, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
113114
})
114115

115116
test_that("Check input: betas", {
116117

117118
### betas is not a matrix or SparseBlockMatrixR
118-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = as.numeric(betas.test), lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
119+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = as.numeric(betas.test), lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
119120

120121
### If betas = zeroes and lambda = sqrt(n), then output should be zero
121-
final <- ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = matrix(0, nrow = pp, ncol = pp), lambda = sqrt(nn), gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test)
122+
final <- ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = matrix(0, nrow = pp, ncol = pp), lambda = sqrt(nn), weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test)
122123
expect_true(is.zero(final$sbm))
123124
})
124125

125126
test_that("Check input: lambda", {
126127

127128
### lambda is negative
128-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = -lambda.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
129+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = -lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
130+
})
131+
132+
test_that("Check input: weights", {
133+
134+
### weight > 1
135+
weights.test <- rep(1, pp*pp)
136+
weights.test[1] <- 2
137+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = -5, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test), "weights out of bounds")
138+
139+
### weight < 1
140+
weights.test <- rep(1, pp*pp)
141+
weights.test[1] <- -2
142+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = -1, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test), "weights out of bounds")
143+
129144
})
130145

131146
test_that("Check input: gamma", {
132147

133148
### gamma is negative
134-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, gamma = -5, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
149+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = -5, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test))
135150

136151
### gamma = -1 is OK
137-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, gamma = -1, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test), NA)
152+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = -1, eps = eps.test, maxIters = maxIters.test, alpha = alpha.test), NA)
138153

139154
})
140155

141156
test_that("Check input: eps", {
142157

143158
### eps is negative
144-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = -5, maxIters = maxIters.test, alpha = alpha.test))
159+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = -5, maxIters = maxIters.test, alpha = alpha.test))
145160

146161
### Output warning if user sets eps = 0
147-
expect_warning(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = 0, maxIters = maxIters.test, alpha = alpha.test))
162+
expect_warning(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = 0, maxIters = maxIters.test, alpha = alpha.test))
148163
})
149164

150165
test_that("Check input: maxIters", {
151166

152167
### maxIters is negative
153-
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, gamma = gamma.test, eps = eps.test, maxIters = -5, alpha = alpha.test))
168+
expect_error(ccdr_singleR(cors = cors.test, pp = pp, nn = nn, betas = betas.test, lambda = lambda.test, weights = weights.test, gamma = gamma.test, eps = eps.test, maxIters = -5, alpha = alpha.test))
154169
})
155170

156171
test_that("Check input: alpha", {

tests/testthat/test-test_cases.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ test_that("If cors = 0 and betas = 0, ouput should be all zeroes (low-dim)", {
1919
final <- ccdr_gridR(cors = cors,
2020
pp = as.integer(pp), nn = as.integer(nn),
2121
betas = matrix(0, nrow = pp, ncol = pp),
22+
weights = rep(1, pp*pp),
2223
alpha = 10, gamma = 2, eps = 1e-4, maxIters = 10L, lambdas = 10:1, verbose = FALSE)
2324

2425
check_zeroes <- check_vars <- TRUE
@@ -43,6 +44,7 @@ test_that("If cors = 0 and betas = 0, ouput should be all zeroes (high-dim)", {
4344
final <- ccdr_gridR(cors = cors,
4445
pp = as.integer(pp), nn = as.integer(nn),
4546
betas = matrix(0, nrow = pp, ncol = pp),
47+
weights = rep(1, pp*pp),
4648
alpha = 10, gamma = 2, eps = 1e-4, maxIters = 10L, lambdas = 10:1, verbose = FALSE)
4749

4850
check_zeroes <- check_vars <- TRUE

0 commit comments

Comments
 (0)