Skip to content

Commit

Permalink
fix unit tests checking plotting properly
Browse files Browse the repository at this point in the history
  • Loading branch information
evaham1 committed Nov 28, 2024
1 parent 64af0ef commit 4f9d359
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 13 deletions.
15 changes: 9 additions & 6 deletions man/perf.assess.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/testthat/test-tune.block.plsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ test_that("tune.block.plsda works and is the same as perf alone and in tune wrap
.expect_numerically_close(tune.res.3$error.rate.per.class$mrna$max.dist[3,2], 0.25)

# check can plot outputs
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune.res.1))
expect_silent(plot(tune.res.2))
expect_silent(plot(tune.res.3))
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-tune.block.splsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ test_that("tune.block.splsda works independently and in tune wrapper the same",
expect_equal(tune11$choice.keepX, tune41$choice.keepX)

# check can plot outputs
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune41))
expect_silent(plot(tune11))

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-tune.mint.plsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ test_that("tune.mint.plsda works and is the same perf alone and in tune wrapper"
.expect_numerically_close(tune.res.3$global.error$BER[1,1], 0.3803556)

# check can plot outputs
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune.res.1))
expect_silent(plot(tune.res.2))
expect_silent(plot(tune.res.3))
Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-tune.mint.splsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ test_that("tune.mint.splsda works", code = {
expect_equal(out$choice.ncomp$ncomp, 1)

# check can plot
expect_silent(plot(out))
pdf(NULL)
on.exit(dev.off())
expect_error(plot(out), NA) # makes note about not being able to plot SD bars

})

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

# check can plot
expect_silent(plot(out))
pdf(NULL)
on.exit(dev.off())
expect_error(plot(out), NA) # makes note about not being able to plot SD bars

})

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-tune.pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ test_that("tune.pca and tune(method='pca') are equivalent", {
expect_equal(object1$ncomp, object2$ncomp)
expect_equal(object1$sdev[1], object2$sdev[1])
# check can plot outputs without errors
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(object1))
expect_silent(plot(object2))
})
2 changes: 2 additions & 0 deletions tests/testthat/test-tune.pls.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ test_that("tune.pls works and is the same as perf alone and in tune wrapper", co
.expect_numerically_close(tune.res.3$measures$Q2$summary[1,3], -0.1304012)

# check can plot outputs
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune.res.1))
expect_silent(plot(tune.res.2))
expect_silent(plot(tune.res.3))
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-tune.plsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ test_that("tune.plsda works and is the same perf alone and in tune wrapper", cod
.expect_numerically_close(tune.plsda.res.3$error.rate$overall[1,1], 0.5106383)

# check can plot
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune.plsda.res.1))
expect_silent(plot(tune.plsda.res.2))
expect_silent(plot(tune.plsda.res.3))
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-tune.rcc.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ test_that("tune.rcc works with Mfold method", code = {
expect_equal(tune.rcc.res$grid1, c(0.00100, 0.25075, 0.50050, 0.75025, 1.00000))

# check can plot
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune.rcc.res))
})

Expand All @@ -34,6 +36,8 @@ test_that("tune.rcc works with loo method", code = {
expect_equal(tune.rcc.res$grid1, c(0.00100, 0.25075, 0.50050, 0.75025, 1.00000))

# check can plot
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune.rcc.res))
})

Expand All @@ -56,6 +60,8 @@ test_that("tune.rcc works in parallel same as in series", code = {
expect_equal(tune.rcc.res$grid2, tune.rcc.res.parallel$grid2)

# check can plot
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune.rcc.res))
expect_silent(plot(tune.rcc.res.parallel))
})
Expand Down Expand Up @@ -86,6 +92,8 @@ test_that("tune.rcc and tune(method='rcc') are equivalent", {
expect_equal(tune.rcc.res.1$grid2, tune.rcc.res.2$grid2)

# check can plot
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(tune.rcc.res.1))
expect_silent(plot(tune.rcc.res.2))

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-tune.spca.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test_that("tune.spca works in serial and parallel", {
expect_equal(object_parallel$choice.keepX[[2]], 5)
.expect_numerically_close(object_parallel$cor.comp$comp1[1,2], 0.3994544)
# test can plot outputs
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(object_serial))
expect_silent(plot(object_parallel))
})
Expand Down Expand Up @@ -81,6 +83,8 @@ test_that("tune.spca and tune(method='spca') are equivalent", {
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
pdf(NULL)
on.exit(dev.off())
expect_silent(plot(object1))
expect_silent(plot(object2))
})
Expand Down
12 changes: 7 additions & 5 deletions tests/testthat/test-tune.splsda.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ test_that("tune.splsda works and is the same in parallel and when run in tune wr
method = "splsda")


# check outputs
# check outputs format
expect_equal(class(tune.splsda.res.1), "tune.splsda")
expect_equal(class(tune.splsda.res.2), "tune.splsda")
expect_equal(class(tune.splsda.res.3), "tune.splsda")
expect_equal(class(tune.splsda.res.4), "tune.splsda")

# check output values
expect_equal(unname(tune.splsda.res.1$choice.keepX), c(10,15))
expect_equal(unname(tune.splsda.res.2$choice.keepX), c(10,15))
expect_equal(unname(tune.splsda.res.3$choice.keepX), c(10,15))
Expand All @@ -46,10 +48,10 @@ test_that("tune.splsda works and is the same in parallel and when run in tune wr
.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))
expect_is(plot(tune.splsda.res.1), "ggplot")
expect_is(plot(tune.splsda.res.2), "ggplot")
expect_is(plot(tune.splsda.res.3), "ggplot")
expect_is(plot(tune.splsda.res.4), "ggplot")

})

Expand Down

0 comments on commit 4f9d359

Please sign in to comment.