diff --git a/tests/testthat/test-fdis.R b/tests/testthat/test-fdis.R index 87c3afc..28cb73c 100644 --- a/tests/testthat/test-fdis.R +++ b/tests/testthat/test-fdis.R @@ -10,9 +10,8 @@ test_that("Functional Dispersion output format", { fdis <- expect_silent(fd_fdis(traits_birds)) expect_s3_class(fdis, "data.frame") - expect_length(fdis, 2) - expect_equal(nrow(fdis), 1) - expect_equal(colnames(fdis), c("site", "FDis")) + expect_identical(dim(fdis), c(1L, 2L)) + expect_named(fdis, c("site", "FDis")) expect_equal(fdis$FDis, 146.2072, tolerance = 1e-7) }) @@ -40,7 +39,7 @@ test_that("Functional Dispersion works for site with no species", { fd_fdis(traits_plants, site_sp_plants[10,, drop = FALSE]) ) - expect_equal(fdis$FDis[[1]], 0) + expect_identical(fdis$FDis[[1]], 0) }) test_that("Functional Dispersion works in 1D", { @@ -64,9 +63,8 @@ test_that("Functional Dispersion works with sparse matrices", { fdis <- expect_silent(fd_fdis(traits_birds, sparse_site_sp)) expect_s3_class(fdis, "data.frame") - expect_length(fdis, 2) - expect_equal(nrow(fdis), 1) - expect_equal(colnames(fdis), c("site", "FDis")) + expect_identical(dim(fdis), c(1L, 2L)) + expect_named(fdis, c("site", "FDis")) expect_equal( fd_fdis(traits_birds, sparse_site_sp), diff --git a/tests/testthat/test-fdiv.R b/tests/testthat/test-fdiv.R index 44ba4ad..d926b73 100644 --- a/tests/testthat/test-fdiv.R +++ b/tests/testthat/test-fdiv.R @@ -10,9 +10,8 @@ test_that("Functional Divergence output format", { fdiv <- expect_silent(fd_fdiv(traits_birds)) expect_s3_class(fdiv, "data.frame") - expect_length(fdiv, 2) - expect_equal(nrow(fdiv), 1) - expect_equal(colnames(fdiv), c("site", "FDiv")) + expect_identical(dim(fdiv), c(1L, 2L)) + expect_named(fdiv, c("site", "FDiv")) expect_equal(fdiv$FDiv, 0.7282172, tolerance = 1e-7) }) @@ -40,7 +39,7 @@ test_that("Functional Divergence works for site with no species", { fd_fdiv(traits_plants, site_sp_plants[10,, drop = FALSE]) ) - expect_equal(fdiv$FDiv[[1]], 0) + expect_identical(fdiv$FDiv[[1]], 0) }) test_that("Functional Divergence works in 1D", { @@ -64,9 +63,8 @@ test_that("Functional Divergence works with sparse matrices", { fdiv <- expect_silent(fd_fdiv(traits_birds, sparse_site_sp)) expect_s3_class(fdiv, "data.frame") - expect_length(fdiv, 2) - expect_equal(nrow(fdiv), 1) - expect_equal(colnames(fdiv), c("site", "FDiv")) + expect_identical(dim(fdiv), c(1L, 2L)) + expect_named(fdiv, c("site", "FDiv")) expect_equal( fd_fdiv(traits_birds, sparse_site_sp), diff --git a/tests/testthat/test-feve.R b/tests/testthat/test-feve.R index 71339b5..e24c290 100644 --- a/tests/testthat/test-feve.R +++ b/tests/testthat/test-feve.R @@ -11,17 +11,15 @@ test_that("Functional Evenness output format", { feve <- expect_silent(fd_feve(traits_birds, sp_com = simple_site_sp)) expect_s3_class(feve, "data.frame") - expect_length(feve, 2) - expect_equal(nrow(feve), 1) - expect_equal(colnames(feve), c("site", "FEve")) + expect_identical(dim(feve), c(1L, 2L)) + expect_named(feve, c("site", "FEve")) feve <- expect_silent(fd_feve(traits_birds)) expect_s3_class(feve, "data.frame") - expect_length(feve, 2) - expect_equal(nrow(feve), 1) - expect_equal(colnames(feve), c("site", "FEve")) + expect_identical(dim(feve), c(1L, 2L)) + expect_named(feve, c("site", "FEve")) }) @@ -41,7 +39,7 @@ test_that("Functional Evenness computation are in line with other packages", { abund_mat <- matrix(1, ncol = 3, dimnames = list("site1", letters[1:3])) - expect_equal(fd_feve(sp_com = abund_mat, dist_matrix = test_dissim)$FEve, 1) + expect_identical(fd_feve(sp_com = abund_mat, dist_matrix = test_dissim)$FEve, 1) }) test_that("Functional Evenness works in 1D", { @@ -71,9 +69,9 @@ test_that("Functional Evenness works on subset of site/species", { test_that("Functional Evenness edge cases", { # n_species = 2 < 3 so not possible to compute FEve - expect_equal(fd_feve(traits_birds[1:2,], + expect_identical(fd_feve(traits_birds[1:2,], simple_site_sp[, 1:2, drop = FALSE])[["FEve"]], - NA_real_) + NA_real_) # n_species = 0, so no definition of FEve @@ -84,7 +82,7 @@ test_that("Functional Evenness edge cases", { fd_feve(traits_plants, site_sp_plants[10,, drop = FALSE]) ) - expect_equal(feve$FEve[[1]], NA_real_) + expect_identical(feve$FEve[[1]], NA_real_) }) test_that("Functional Evenness works on sparse matrices", { @@ -102,21 +100,26 @@ test_that("Functional Evenness works on sparse matrices", { # Only site-species matrix is sparse expect_silent(fd_feve(traits_birds, sparse_site_sp)) - expect_equal(fd_feve(traits_birds, sparse_site_sp)$FEve, 0.3743341, - tolerance = 1e-6) + expect_equal( + fd_feve(traits_birds, sparse_site_sp), + fd_feve(traits_birds, site_sp) + ) # Only distance matrix is sparse expect_silent(fd_feve(sp_com = site_sp, dist_matrix = sparse_dist_mat)) - expect_equal(fd_feve(sp_com = site_sp, dist_matrix = sparse_dist_mat)$FEve, - 0.3743341, tolerance = 1e-6) + expect_equal( + fd_feve(sp_com = site_sp, dist_matrix = sparse_dist_mat), + fd_feve(sp_com = site_sp, dist_matrix = dist(traits_birds)) + ) # Both site-species and distance matrix are sparse expect_silent(fd_feve(sp_com = sparse_site_sp, dist_matrix = sparse_dist_mat)) expect_equal( - fd_feve(sp_com = sparse_site_sp, dist_matrix = sparse_dist_mat)$FEve, - 0.3743341, tolerance = 1e-6) + fd_feve(sp_com = sparse_site_sp, dist_matrix = sparse_dist_mat), + fd_feve(sp_com = site_sp, dist_matrix = dist(traits_birds)) + ) }) diff --git a/tests/testthat/test-fric.R b/tests/testthat/test-fric.R index 5b1c34f..57406fc 100644 --- a/tests/testthat/test-fric.R +++ b/tests/testthat/test-fric.R @@ -9,9 +9,8 @@ test_that("Functional Richness output format", { fric <- expect_silent(fd_fric(traits_birds)) expect_s3_class(fric, "data.frame") - expect_length(fric, 2) - expect_equal(nrow(fric), 1) - expect_equal(colnames(fric), c("site", "FRic")) + expect_identical(dim(fric), c(1L, 2L)) + expect_named(fric, c("site", "FRic")) expect_equal(fd_fric(traits_birds)$FRic, 230967.7, tolerance = 1e-6) }) @@ -58,8 +57,8 @@ test_that("Functional Richness can standardize its values", { fric <- fd_fric(traits_birds, stand = TRUE) fric_low_1 <- suppressMessages(fd_fric(traits_birds, site_sp2, stand = TRUE)) - expect_equal(fric$FRic[[1]], 1) - expect_equal(fric_low_1$FRic[[1]], 1) + expect_identical(fric$FRic[[1]], 1) + expect_identical(fric_low_1$FRic[[1]], 1) expect_lt(fric_low_1$FRic[[2]], 1) }) @@ -107,7 +106,7 @@ test_that("Functional Richness edge cases", { fd_fric(traits_plants, site_sp_plants[10,, drop = FALSE]) ) - expect_equal(fric$FRic[[1]], NA_real_) + expect_identical(fric$FRic[[1]], NA_real_) }) @@ -121,10 +120,11 @@ test_that("Functional Richness works on sparse matrices", { sparse_site_sp <- Matrix(site_sp, sparse = TRUE) - expect_silent(fd_fric(traits_birds, sparse_site_sp)) + sparse_fric <- expect_silent(fd_fric(traits_birds, sparse_site_sp)) - expect_equal(fd_fric(traits_birds, sparse_site_sp)$FRic, 230967.7, - tolerance = 1e-6) + fric <- expect_silent(fd_fric(traits_birds, site_sp)) + + expect_equal(fric, sparse_fric) }) diff --git a/tests/testthat/test-fric_intersect.R b/tests/testthat/test-fric_intersect.R index 1c2d31b..927a531 100644 --- a/tests/testthat/test-fric_intersect.R +++ b/tests/testthat/test-fric_intersect.R @@ -10,10 +10,8 @@ test_that("Functional Richness Intersection output format", { fric_int <- expect_silent(fd_fric_intersect(traits_birds)) expect_s3_class(fric_int, "data.frame") - expect_length(fric_int, 3) - expect_equal(nrow(fric_int), 1) - expect_equal(colnames(fric_int), c("first_site", "second_site", - "FRic_intersect")) + expect_identical(dim(fric_int), c(1L, 3L)) + expect_named(fric_int, c("first_site", "second_site", "FRic_intersect")) expect_equal(fd_fric_intersect(traits_birds, stand = TRUE)$FRic_intersect, 1, tolerance = 1e-6) @@ -65,8 +63,8 @@ test_that("Functional Richness Intersection can standardize its values", { fric_int_low_1 <- suppressMessages(fd_fric_intersect(traits_birds, site_sp2, stand = TRUE)) - expect_equal(fric_int$FRic_intersect[[1]], 1) - expect_equal(fric_int_low_1$FRic_intersect[[2]], 1) + expect_identical(fric_int$FRic_intersect[[1]], 1) + expect_identical(fric_int_low_1$FRic_intersect[[2]], 1) expect_lt(fric_int_low_1$FRic_intersect[[3]], 1) expect_lt(fric_int_low_1$FRic_intersect[[1]], 1) }) @@ -131,7 +129,7 @@ test_that("Functional Richness Intersection edge cases", { fd_fric_intersect(traits_plants, site_sp_plants[10,, drop = FALSE]) ) - expect_equal(fric_inter$FRic_intersect[[1]], NA_real_) + expect_identical(fric_inter$FRic_intersect[[1]], NA_real_) }) test_that("Functional Richness Intersection works on sparse matrices", { diff --git a/tests/testthat/test-raoq.R b/tests/testthat/test-raoq.R index ed5e1f1..3f335e0 100644 --- a/tests/testthat/test-raoq.R +++ b/tests/testthat/test-raoq.R @@ -11,17 +11,15 @@ test_that("Rao's entropy output format", { rq <- expect_silent(fd_raoq(traits_birds, sp_com = simple_site_sp)) expect_s3_class(rq, "data.frame") - expect_length(rq, 2) - expect_equal(nrow(rq), 1) - expect_equal(colnames(rq), c("site", "Q")) + expect_identical(dim(rq), c(1L, 2L)) + expect_named(rq, c("site", "Q")) rq <- expect_silent(fd_raoq(traits_birds)) expect_s3_class(rq, "data.frame") - expect_length(rq, 2) - expect_equal(nrow(rq), 1) - expect_equal(colnames(rq), c("site", "Q")) + expect_identical(dim(rq), c(1L, 2L)) + expect_named(rq, c("site", "Q")) }) @@ -62,7 +60,7 @@ test_that("Rao's quadratric entropy works for sites with no species", { fd_raoq(traits_plants, site_sp_plants[10,, drop = FALSE]) ) - expect_equal(raoq$Q[[1]], 0) + expect_identical(raoq$Q[[1]], 0) }) test_that("Rao's Quadratic Entropy works on sparse matrices", { @@ -80,21 +78,26 @@ test_that("Rao's Quadratic Entropy works on sparse matrices", { # Only site-species matrix is sparse expect_silent(fd_raoq(traits_birds, sparse_site_sp)) - expect_equal(fd_raoq(traits_birds, sparse_site_sp)$Q, 170.0519, - tolerance = 1e-6) + expect_equal( + fd_raoq(traits_birds, sparse_site_sp), + fd_raoq(traits_birds, site_sp) + ) # Only distance matrix is sparse expect_silent(fd_raoq(sp_com = site_sp, dist_matrix = sparse_dist_mat)) - expect_equal(fd_raoq(sp_com = site_sp, dist_matrix = sparse_dist_mat)$Q, - 170.0519, tolerance = 1e-6) + expect_equal( + fd_raoq(sp_com = site_sp, dist_matrix = sparse_dist_mat), + fd_raoq(sp_com = site_sp, dist_matrix = dist(traits_birds)) + ) # Both site-species and distance matrix are sparse expect_silent(fd_raoq(sp_com = sparse_site_sp, dist_matrix = sparse_dist_mat)) expect_equal( - fd_raoq(sp_com = sparse_site_sp, dist_matrix = sparse_dist_mat)$Q, - 170.0519, tolerance = 1e-6) + fd_raoq(sp_com = sparse_site_sp, dist_matrix = sparse_dist_mat), + fd_raoq(sp_com = site_sp, dist_matrix = dist(traits_birds)) + ) }) diff --git a/tests/testthat/test-remove_species_without_trait.R b/tests/testthat/test-remove_species_without_trait.R index 98c9373..d7f157c 100644 --- a/tests/testthat/test-remove_species_without_trait.R +++ b/tests/testthat/test-remove_species_without_trait.R @@ -3,7 +3,7 @@ test_that("remove_species_without_trait() works", { data("traits_birds") expect_silent(remove_species_without_trait(traits_birds)) - expect_equal(remove_species_without_trait(traits_birds), traits_birds) + expect_identical(remove_species_without_trait(traits_birds), traits_birds) traits_birds_missing <- traits_birds traits_birds_missing[1, 1] <- NA @@ -16,7 +16,7 @@ test_that("remove_species_without_trait() works", { traits_birds_missing[2, 2] <- NA - expect_equal( + expect_identical( suppressMessages(remove_species_without_trait(traits_birds_missing)), traits_birds_missing[3:nrow(traits_birds), ]) expect_message(remove_species_without_trait(traits_birds_missing),