Skip to content

Commit

Permalink
add testing to make sure tune outputs can plot without error
Browse files Browse the repository at this point in the history
  • Loading branch information
evaham1 committed Nov 27, 2024
1 parent 7f255db commit 64af0ef
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/testthat/test-tune.block.plsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ test_that("tune.block.plsda works and is the same as perf alone and in tune wrap
.expect_numerically_close(tune.res.2$error.rate.per.class$mrna$max.dist[3,2], 0.25)
.expect_numerically_close(tune.res.3$error.rate.per.class$mrna$max.dist[3,2], 0.25)

# check can plot outputs
expect_silent(plot(tune.res.1))
expect_silent(plot(tune.res.2))
expect_silent(plot(tune.res.3))

})


5 changes: 5 additions & 0 deletions tests/testthat/test-tune.block.splsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ test_that("tune.block.splsda works independently and in tune wrapper the same",
BPPARAM = SerialParam(), seed = 42
)
expect_equal(tune11$choice.keepX, tune41$choice.keepX)

# check can plot outputs
expect_silent(plot(tune41))
expect_silent(plot(tune11))

})

test_that("tune.block.splsda works when test.keepX = NULL and gives same result as perf()", code = {
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-tune.mint.plsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,10 @@ test_that("tune.mint.plsda works and is the same perf alone and in tune wrapper"
.expect_numerically_close(tune.res.2$global.error$BER[1,1], 0.3803556)
.expect_numerically_close(tune.res.3$global.error$BER[1,1], 0.3803556)

# check can plot outputs
expect_silent(plot(tune.res.1))
expect_silent(plot(tune.res.2))
expect_silent(plot(tune.res.3))


})
6 changes: 6 additions & 0 deletions tests/testthat/test-tune.mint.splsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ test_that("tune.mint.splsda works", code = {
expect_is(out, "tune.mint.splsda")
expect_equal(out$choice.ncomp$ncomp, 1)

# check can plot
expect_silent(plot(out))

})

test_that("tune.mint.splsda works with custom alpha", code = {
Expand All @@ -43,6 +46,9 @@ test_that("tune.mint.splsda works with custom alpha", code = {
expect_is(out, "tune.mint.splsda")
expect_equal(out$choice.ncomp$ncomp, 1)

# check can plot
expect_silent(plot(out))

})

test_that("tune.mint.splsda works when test.keepX = NULL and gives same result as perf()", code = {
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-tune.pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ test_that("tune.pca and tune(method='pca') are equivalent", {
# expect results the same
expect_equal(object1$ncomp, object2$ncomp)
expect_equal(object1$sdev[1], object2$sdev[1])
# check can plot outputs without errors
expect_silent(plot(object1))
expect_silent(plot(object2))
})
5 changes: 5 additions & 0 deletions tests/testthat/test-tune.pls.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ test_that("tune.pls works and is the same as perf alone and in tune wrapper", co
.expect_numerically_close(tune.res.2$measures$Q2$summary[1,3], -0.1304012)
.expect_numerically_close(tune.res.3$measures$Q2$summary[1,3], -0.1304012)

# check can plot outputs
expect_silent(plot(tune.res.1))
expect_silent(plot(tune.res.2))
expect_silent(plot(tune.res.3))

})

5 changes: 5 additions & 0 deletions tests/testthat/test-tune.plsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ test_that("tune.plsda works and is the same perf alone and in tune wrapper", cod
.expect_numerically_close(tune.plsda.res.2$error.rate$overall[1,1], 0.5106383)
.expect_numerically_close(tune.plsda.res.3$error.rate$overall[1,1], 0.5106383)

# check can plot
expect_silent(plot(tune.plsda.res.1))
expect_silent(plot(tune.plsda.res.2))
expect_silent(plot(tune.plsda.res.3))

})
14 changes: 14 additions & 0 deletions tests/testthat/test-tune.rcc.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ test_that("tune.rcc works with Mfold method", code = {
expect_equal(class(tune.rcc.res), "tune.rcc")
expect_equal(tune.rcc.res$opt.lambda1, 0.5005)
expect_equal(tune.rcc.res$grid1, c(0.00100, 0.25075, 0.50050, 0.75025, 1.00000))

# check can plot
expect_silent(plot(tune.rcc.res))
})

test_that("tune.rcc works with loo method", code = {
Expand All @@ -29,6 +32,9 @@ test_that("tune.rcc works with loo method", code = {
expect_equal(class(tune.rcc.res), "tune.rcc")
expect_equal(tune.rcc.res$opt.lambda1, 0.25075)
expect_equal(tune.rcc.res$grid1, c(0.00100, 0.25075, 0.50050, 0.75025, 1.00000))

# check can plot
expect_silent(plot(tune.rcc.res))
})

test_that("tune.rcc works in parallel same as in series", code = {
Expand All @@ -48,6 +54,10 @@ test_that("tune.rcc works in parallel same as in series", code = {
expect_equal(class(tune.rcc.res), "tune.rcc")
expect_equal(tune.rcc.res$opt.lambda2, tune.rcc.res.parallel$opt.lambda2)
expect_equal(tune.rcc.res$grid2, tune.rcc.res.parallel$grid2)

# check can plot
expect_silent(plot(tune.rcc.res))
expect_silent(plot(tune.rcc.res.parallel))
})

test_that("tune.rcc and tune(method='rcc') are equivalent", {
Expand Down Expand Up @@ -75,5 +85,9 @@ test_that("tune.rcc and tune(method='rcc') are equivalent", {
expect_equal(tune.rcc.res.1$opt.lambda2, tune.rcc.res.2$opt.lambda2)
expect_equal(tune.rcc.res.1$grid2, tune.rcc.res.2$grid2)

# check can plot
expect_silent(plot(tune.rcc.res.1))
expect_silent(plot(tune.rcc.res.2))

})

6 changes: 6 additions & 0 deletions tests/testthat/test-tune.spca.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ test_that("tune.spca works in serial and parallel", {
expect_equal(object_parallel$choice.keepX[[1]], 35)
expect_equal(object_parallel$choice.keepX[[2]], 5)
.expect_numerically_close(object_parallel$cor.comp$comp1[1,2], 0.3994544)
# test can plot outputs
expect_silent(plot(object_serial))
expect_silent(plot(object_parallel))
})

test_that("tune.spca same result in serial and parallel", {
Expand Down Expand Up @@ -77,5 +80,8 @@ test_that("tune.spca and tune(method='spca') are equivalent", {
expect_equal(object1$choice.keepX[[1]], object2$choice.keepX[[1]])
expect_equal(object1$choice.keepX[[2]], object2$choice.keepX[[2]])
.expect_numerically_close(object1$cor.comp$comp1[3,3], object2$cor.comp$comp1[3,3])
# test can plot outputs
expect_silent(plot(object1))
expect_silent(plot(object2))
})

6 changes: 6 additions & 0 deletions tests/testthat/test-tune.spls.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ test_that("tune.spls works and is the same in parallel and when run in tune wrap
.expect_numerically_close(tune.spls.res.1$measure.pred$mean, tune.spls.res.2$measure.pred$mean)
.expect_numerically_close(tune.spls.res.1$measure.pred$mean, tune.spls.res.3$measure.pred$mean)
.expect_numerically_close(tune.spls.res.1$measure.pred$mean, tune.spls.res.4$measure.pred$mean)

# check can plot outputs
expect_silent(plot(tune.spls.res.1))
expect_silent(plot(tune.spls.res.2))
expect_silent(plot(tune.spls.res.3))
expect_silent(plot(tune.spls.res.4))
})

## If ncol(Y) == 1 tune.spls calls tune.spls1
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-tune.splsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ test_that("tune.splsda works and is the same in parallel and when run in tune wr
.expect_numerically_close(tune.splsda.res.3$error.rate[1,1], 0.3111111)
.expect_numerically_close(tune.splsda.res.4$error.rate[1,1], 0.3111111)

# check can plot outputs
expect_silent(plot(tune.splsda.res.1))
expect_silent(plot(tune.splsda.res.2))
expect_silent(plot(tune.splsda.res.3))
expect_silent(plot(tune.splsda.res.4))

})

test_that("tune.splsda works when test.keepX = NULL and gives same result as perf()", code = {
Expand Down

0 comments on commit 64af0ef

Please sign in to comment.