From e4cd2d9a170ed6863d2da898605d88dcb749277a Mon Sep 17 00:00:00 2001 From: Tuomas Borman Date: Tue, 7 Jan 2025 20:59:14 +0200 Subject: [PATCH] Update tests --- tests/testthat/test-0diversity.R | 14 +++++++------- tests/testthat/test-5dominance.R | 8 +++++--- tests/testthat/test-5evenness.R | 5 +++-- tests/testthat/test-5richness.R | 11 ++++++----- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/testthat/test-0diversity.R b/tests/testthat/test-0diversity.R index 7ff317c80..75a801d1d 100644 --- a/tests/testthat/test-0diversity.R +++ b/tests/testthat/test-0diversity.R @@ -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)) @@ -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)) @@ -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) diff --git a/tests/testthat/test-5dominance.R b/tests/testthat/test-5dominance.R index 5278058ea..21cd682e6 100644 --- a/tests/testthat/test-5dominance.R +++ b/tests/testthat/test-5dominance.R @@ -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)) @@ -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 diff --git a/tests/testthat/test-5evenness.R b/tests/testthat/test-5evenness.R index 27957183e..1592eb336 100644 --- a/tests/testthat/test-5evenness.R +++ b/tests/testthat/test-5evenness.R @@ -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") diff --git a/tests/testthat/test-5richness.R b/tests/testthat/test-5richness.R index bb1955f73..7269081cd 100644 --- a/tests/testthat/test-5richness.R +++ b/tests/testthat/test-5richness.R @@ -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 @@ -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)) @@ -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") )