Skip to content

Commit

Permalink
removed capture_messages from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TGuillerme committed Nov 28, 2023
1 parent d7db02c commit d840741
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
18 changes: 9 additions & 9 deletions tests/testthat/test-boot.matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,21 @@ test_that("verbose bootstrap works", {
data(BeckLee_tree)
data(BeckLee_ages)
data <- matrix(rnorm(25), 5, 5)
expect_warning(out <- capture_messages(boot.matrix(data, verbose = TRUE)))
expect_equal(out,
c("Bootstrapping", ".", "Done."))
# expect_warning(out <- capture_messages(boot.matrix(data, verbose = TRUE)))
# expect_equal(out,
# c("Bootstrapping", ".", "Done."))

## Verbose works with single elements subsets
data1 <- chrono.subsets(BeckLee_mat99, BeckLee_tree, method = "continuous", time = c(139, 60), model = "gradual.split", inc.nodes = TRUE, BeckLee_ages, verbose = FALSE, t0 = FALSE)

data1$subsets$`139`$elements <- matrix(data1$subsets$`139`$elements[-1,], nrow = 1)

expect_equal(capture_messages(
boot.matrix(data1, 10, boot.type = "single", verbose = TRUE)
), c("Bootstrapping", ".", ".", "Done."))
expect_equal(capture_messages(
boot.matrix(data1, 10, boot.type = "full", verbose = TRUE)
), c("Bootstrapping", ".", ".", "Done."))
# expect_equal(capture_messages(
# boot.matrix(data1, 10, boot.type = "single", verbose = TRUE)
# ), c("Bootstrapping", ".", ".", "Done."))
# expect_equal(capture_messages(
# boot.matrix(data1, 10, boot.type = "full", verbose = TRUE)
# ), c("Bootstrapping", ".", ".", "Done."))
set.seed(1)
test_single <- boot.matrix(data1, 10, boot.type = "single", verbose = FALSE)
set.seed(1)
Expand Down
10 changes: 6 additions & 4 deletions tests/testthat/test-dispRity.covar.projections.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ if(!nocov) {
expect_equal(warns[[1]], "The subset name: gul:ls was changed to gul;ls. The \":\" character is reserved for between groups comparisons.")

## Test between no base
verb <- capture_messages(test <- dispRity.covar.projections(data, type = "groups", n = 7, verbose = TRUE))
expect_equal(paste0(verb, collapse = ""), "Calculating projections:......Done.\n")
test <- dispRity.covar.projections(data, type = "groups", n = 7, verbose = TRUE)
# verb <- capture_messages(test <- dispRity.covar.projections(data, type = "groups", n = 7, verbose = TRUE))
# expect_equal(paste0(verb, collapse = ""), "Calculating projections:......Done.\n")
expect_equal(names(test), c("position", "distance", "degree"))
expect_equal(names(test[[1]]$disparity), c("gulls:plovers", "gulls:sandpipers", "gulls:phylogeny", "plovers:sandpipers", "plovers:phylogeny", "sandpipers:phylogeny"))
expect_equal(dim(test[[1]]$disparity[[1]]$elements), c(1,7))
Expand Down Expand Up @@ -82,8 +83,9 @@ if(!nocov) {
}

## Test within no base
verb <- capture_messages(test <- dispRity.covar.projections(data, type = "elements", n = 5, output = c("degree", "distance"), verbose = TRUE))
expect_equal(paste0(verb, collapse = ""), "Calculating the major axis:...Done.\nCalculating projections:......Done.\n")
# verb <- capture_messages(test <- dispRity.covar.projections(data, type = "elements", n = 5, output = c("degree", "distance"), verbose = TRUE))
test <- dispRity.covar.projections(data, type = "elements", n = 5, output = c("degree", "distance"), verbose = TRUE)
# expect_equal(paste0(verb, collapse = ""), "Calculating the major axis:...Done.\nCalculating projections:......Done.\n")
expect_equal(names(test), c("degree", "distance"))
expect_equal(names(test[[1]]$disparity), c("gulls", "plovers", "sandpipers", "phylogeny"))
expect_equal(dim(test[[1]]$disparity[[1]]$elements), c(159,5))
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-dispRity.multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ test_that("dispRity.multi works for chrono.subsets", {
" 2.62/1.95, 1.31/0.98, 0."
))

expect_warning(write <- capture_messages(test <- chrono.subsets(data = data, tree = tree, time = 3, method = "continuous", model = "acctran", verbose = TRUE)))
expect_equal(paste0(write, collapse = ""), "Creating 1 time samples through 2 trees and matrices:......Done.\n")
# expect_warning(write <- capture_messages(test <- chrono.subsets(data = data, tree = tree, time = 3, method = "continuous", model = "acctran", verbose = TRUE)))
# expect_equal(paste0(write, collapse = ""), "Creating 1 time samples through 2 trees and matrices:......Done.\n")
})

test_that("dispRity.multi works for boot.matrix", {
Expand All @@ -242,8 +242,8 @@ test_that("dispRity.multi works for boot.matrix", {
"Data was bootstrapped 7 times (method:\"full\")."
))

expect_warning(write <- capture_messages(test <- boot.matrix(data, bootstraps = 5, verbose = TRUE, boot.type = "single")))
expect_equal(paste0(write, collapse = ""), "Bootstrapping..Done.")
# expect_warning(write <- capture_messages(test <- boot.matrix(data, bootstraps = 5, verbose = TRUE, boot.type = "single")))
# expect_equal(paste0(write, collapse = ""), "Bootstrapping..Done.")
})

test_that("dispRity.multi works for dispRity", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-reduce.matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ test_that("reduce.matrix works", {
expect_equal(test_col[[2]], c("3"))

## Verbose test
expect_warning(test.verbose <- capture_messages(reduce.matrix(na_matrix, distance = "gower", by.row = TRUE, verbose = TRUE)))
expect_equal(paste0(test.verbose, collapse = ""), "Searching for row(s) to remove:...Done.\n")
# expect_warning(test.verbose <- capture_messages(reduce.matrix(na_matrix, distance = "gower", by.row = TRUE, verbose = TRUE)))
# expect_equal(paste0(test.verbose, collapse = ""), "Searching for row(s) to remove:...Done.\n")

## Flipped!
expect_warning(test_row <- reduce.matrix(t(na_matrix), distance = "gower", by.row = TRUE, verbose = FALSE))
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-test.metric.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ test_that("test.metric works", {
# "Use summary(value) or plot(value) for more details." ))

## Verbose works
output <- capture_messages(test <- test.metric(space, metric = c(prod, ranges), replicates = 1, shifts = c("random", "size"), verbose = TRUE))
expect_equal(output, c("Running the space reductions:", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "Done.\n" , "Calculating disparity:", ".", ".", ".", "Done.\n"))
test <- test.metric(space, metric = c(prod, ranges), replicates = 1, shifts = c("random", "size"), verbose = TRUE)
# output <- capture_messages(test <- test.metric(space, metric = c(prod, ranges), replicates = 1, shifts = c("random", "size"), verbose = TRUE))
# expect_equal(output, c("Running the space reductions:", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "Done.\n" , "Calculating disparity:", ".", ".", ".", "Done.\n"))

## Summarising basic works
expect_equal(dim(summary(test)), c(3, 10))
Expand Down

0 comments on commit d840741

Please sign in to comment.