Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TuomasBorman committed Jan 7, 2025
1 parent 9d48076 commit e4cd2d9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
14 changes: 7 additions & 7 deletions tests/testthat/test-0diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_that("diversity estimates", {
indices <- c("coverage", "fisher", "gini_simpson", "faith",
"inverse_simpson", "log_modulo_skewness",
"shannon")
tse_idx <- .estimate_diversity(tse, index = indices, threshold = 0.473)
tse_idx <- addAlpha(tse, index = indices, threshold = 0.473)

# Checks that the type of output is the same as the type of input.
expect_true(typeof(tse_idx) == typeof(tse))
Expand Down Expand Up @@ -43,7 +43,7 @@ test_that("diversity estimates", {

# Tests that 'quantile' and 'nclasses' are working
expect_equal(unname(round(colData(
.estimate_diversity(
addAlpha(
tse, index="log_modulo_skewness", quantile=0.855,nclasses=32)
)$log_modulo_skewness, 6)), c(1.814770, 1.756495, 1.842704))

Expand Down Expand Up @@ -121,16 +121,16 @@ test_that("diversity estimates", {
data(GlobalPatterns, package="mia")
data(esophagus, package="mia")
tse <- mergeSEs(GlobalPatterns, esophagus, join = "full", assay.type = "counts")
expect_error(.estimate_diversity(tse, index = c("shannon", "faith"),
expect_error(addAlpha(tse, index = c("shannon", "faith"),
tree.name = "phylo.1", assay.type="counts"))
expect_error(.estimate_diversity(tse, index = c("faith"),
expect_error(addAlpha(tse, index = c("faith"),
tree.name = "test"))
expect_error(.estimate_diversity(tse, index = c("shannon", "faith"),
expect_error(addAlpha(tse, index = c("shannon", "faith"),
tree.name = TRUE))
expect_error(.estimate_diversity(tse, index = c("shannon", "faith"),
expect_error(addAlpha(tse, index = c("shannon", "faith"),
tree.name = 1))

expect_error(.estimate_diversity(tse, index = c("shannon", "faith"),
expect_error(addAlpha(tse, index = c("shannon", "faith"),
tree.name = c("phylo", "phylo.1")))

# Test Faith with picante packages results (version 1.8.2)
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/test-5dominance.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ test_that(".estimate_dominance", {

#.estimate_dominance
#Calculates all indices.
tse_idx <- .estimate_dominance(tse)
indices <- c(
"absolute", "dbp", "core_abundance", "gini", "dmn", "relative",
"simpson_lambda")
tse_idx <- addAlpha(tse, index = indices)

#Checks that the type of output is the same as the type of input.
expect_true(typeof(tse_idx) == typeof(tse))
Expand All @@ -22,8 +25,7 @@ test_that(".estimate_dominance", {
#in the input vector.
expect_named(
colData(tse_idx),
c("absolute", "dbp", "core_abundance", "gini", "dmn", "relative",
"simpson_lambda"))
indices)

#.calc_core_dominance
#Rounded because, without it gave an error (average difference was
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-5evenness.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ test_that(".estimate_evenness", {
# colData.
# Check that the order of indices is right / the same as the order
# in the input vector.
tse_idx <- .estimate_evenness(tse)
indices <- c("camargo", "pielou", "simpson_evenness", "evar", "bulla")
tse_idx <- addAlpha(tse, index = indices)

# Check that the type of output is the same as the type of input.
expect_true(typeof(tse_idx) == typeof(tse))

expect_named(
colData(tse_idx),
c("camargo", "pielou", "simpson_evenness", "evar", "bulla"))
indices)

mat <- assay(tse_idx,"counts")

Expand Down
11 changes: 6 additions & 5 deletions tests/testthat/test-5richness.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ test_that(".estimate_richness", {

skip_if_not(requireNamespace("vegan", quietly = TRUE))
data(esophagus, package="mia")

tse <- .estimate_richness(esophagus, detection = 1)

indices <- c("ace", "chao1", "hill", "observed")
tse <- addAlpha(esophagus, index = indices, detection = 1)
cd <- colData(tse)
expect_equal(unname(round(cd$observed, 0)), c(15, 24, 16))
# These are unaffected by detection parameter
Expand All @@ -17,7 +18,7 @@ test_that(".estimate_richness", {
test_internal_.estimate_richness <- function(tse){

# Calculate all indices.
tse_idx <- .estimate_richness(tse)
tse_idx <- addAlpha(tse, index = indices)

# Check that the type of output is the same as the type of input.
expect_true(typeof(tse_idx) == typeof(tse))
Expand All @@ -31,10 +32,10 @@ test_that(".estimate_richness", {
c("ace", "ace_se", "chao1", "chao1_se", "hill", "observed"))

# Delete colData
colData(tse_idx) <- NULL
colData(tse_idx) <- NULL

# Calculate all indices with specified names
tse_idx <- .estimate_richness(tse,
tse_idx <- addAlpha(tse,
index = c("observed", "chao1", "ace", "hill"),
name = c("Observed", "Chao1", "ACE", "Hill")
)
Expand Down

0 comments on commit e4cd2d9

Please sign in to comment.