Skip to content

Commit 35c75a0

Browse files
committed
Added code coverage and added a codecov token
1 parent 339b06e commit 35c75a0

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

.github/workflows/rhub.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- name: Bad CXXFLAGS for atlas
8585
if: matrix.config.label == 'atlas'
8686
# throws a warning on non-portable compilation flags
87-
# Can's set _R_CHECK_COMPILATION_FLAGS_=FALSE because --as-cran resets it
87+
# Can't set _R_CHECK_COMPILATION_FLAGS_=FALSE because --as-cran resets it
8888
# instead, allow for the flags that are a problem
8989
run: |
9090
echo '_R_CHECK_COMPILATION_FLAGS_KNOWN_="-Werror=format-security -Werror=implicit-function-declaration -Wno-ignored-attributes -Wno-parentheses -Wp,-D_FORTIFY_SOURCE=3"' >> $GITHUB_ENV

codecov.yml

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ coverage:
1010
default:
1111
target: auto
1212
threshold: 1%
13+
14+
codecov:
15+
token: 5037e846-ad23-45bb-a691-27f5fbcb94e5

tests/testthat/test-correlatedLHS.R

+35
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@ test_that("Normal Operations", {
1414
expect_true(is.numeric(temp$cost))
1515
expect_true(is.matrix(temp$lhs))
1616
expect_true(is.matrix(temp$transformed_lhs))
17+
18+
# debug
19+
expect_output(temp <- correlatedLHS(randomLHS(10, 3),
20+
marginal_transform_function = function(x, ...) {
21+
x[,1] <- qunif(x[,1], 3, 6)
22+
return(x)
23+
},
24+
cost_function = function(x, ...) {
25+
(cor(x[,1], x[,2]) - 0.8)^2
26+
}, debug = TRUE))
1727
})
1828

1929
test_that("problems", {
2030
# bad marginal_transform_function return
31+
# not a data.frame or matrix
2132
expect_error({
2233
correlatedLHS(randomLHS(10, 3),
2334
marginal_transform_function = function(x, ...) {
@@ -28,6 +39,17 @@ test_that("problems", {
2839
})
2940
})
3041

42+
# wrong dimensions
43+
expect_error({
44+
correlatedLHS(randomLHS(10, 3),
45+
marginal_transform_function = function(x, ...) {
46+
return(matrix(1, nrow = 2, ncol = 2))
47+
},
48+
cost_function = function(x, ...) {
49+
return(1)
50+
})
51+
})
52+
3153
# bad cost_function return
3254
expect_error({
3355
correlatedLHS(randomLHS(10, 3),
@@ -63,4 +85,17 @@ test_that("problems", {
6385
test_var = "A")
6486
})
6587

88+
# bad lhs
89+
expect_output(
90+
expect_error(
91+
temp <- correlatedLHS(matrix(-1, nrow = 2, ncol = 2),
92+
marginal_transform_function = function(x, ...) {
93+
return(x)
94+
},
95+
cost_function = function(x, ...) {
96+
return(sum(x))
97+
}, debug = TRUE)
98+
)
99+
)
100+
66101
})

tests/testthat/test-galois_field.R

+37
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,40 @@ test_that("Roots", {
160160
check_roots(create_galois_field(9))
161161
check_roots(create_galois_field(8))
162162
})
163+
164+
test_that("poly_prod", {
165+
gf <- create_galois_field(4)
166+
# poly_prod(gf$p, gf$n, gf$xton, gf$poly[1,], gf$poly[2,])
167+
# n != length(xton)
168+
expect_error(poly_prod(gf$p, gf$n, gf$xton[1], gf$poly[1,], gf$poly[2,]))
169+
# n != length(p1)
170+
expect_error(poly_prod(gf$p, gf$n, gf$xton, gf$poly[1,1], gf$poly[2,]))
171+
# n != length(p2)
172+
expect_error(poly_prod(gf$p, gf$n, gf$xton, gf$poly[1,], gf$poly[2,1]))
173+
# entries of polynomials > p
174+
expect_error(poly_prod(gf$p, gf$n, gf$xton, c(7,7), gf$poly[2,]))
175+
# entries of polynomials < 0
176+
expect_error(poly_prod(gf$p, gf$n, gf$xton, c(-7,-7), gf$poly[2,]))
177+
})
178+
179+
test_that("poly_sum", {
180+
gf <- create_galois_field(4)
181+
# n != length(p1)
182+
expect_error(poly_sum(gf$p, gf$n, gf$poly[1,1], gf$poly[2,]))
183+
# n != length(p2)
184+
expect_error(poly_sum(gf$p, gf$n, gf$poly[1,], gf$poly[2,1]))
185+
# entries of polynomials > p
186+
expect_error(poly_sum(gf$p, gf$n, c(7,7), gf$poly[2,]))
187+
# entries of polynomials < 0
188+
expect_error(poly_sum(gf$p, gf$n, c(-7,-7), gf$poly[2,]))
189+
})
190+
191+
test_that("poly2int", {
192+
gf <- create_galois_field(4)
193+
# n != length(poly)
194+
expect_error(poly2int(gf$p, gf$n, gf$poly[1,1]))
195+
# entries of polynomials > p
196+
expect_error(poly2int(gf$p, gf$n, c(7,7)))
197+
# entries of polynomials < 0
198+
expect_error(poly2int(gf$p, gf$n, c(-7,-7)))
199+
})

0 commit comments

Comments
 (0)