Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 14 additions & 33 deletions tests/testthat/test-canopy_service_test.R
Original file line number Diff line number Diff line change
@@ -1,49 +1,30 @@
#################################################
#Tests para canopy_service_test
#################################################

#library(testthat)
res <- canopy_service_test(Amoladeras_int, Amoladeras_cover)

#load data
mypath<-getwd()
download_RN() # Run only the first time you use the package.
setwd(mypath)
RecruitNet <-read.csv("RecruitNet.csv")
CanopyCover <-read.csv("CanopyCover.csv")
test_that("canopy_service_test data.frame with correct columns", {

mysite_com <- comm_subset_UNI(RecruitNet, "Amoladeras")
mysite_cov <- comm_subset_UNI(CanopyCover, "Amoladeras")

#------------------------------------

test_that("canopy_service_test devuelve un data.frame con las columnas correctas", {

res <- canopy_service_test(mysite_com, mysite_cov)

expect_s3_class(res, "data.frame")

expect_equal(
colnames(res),
c("Canopy", "Fc", "Ac", "Fro", "Ao",
"testability", "Significance", "Test_type", "Canopy_effect")
)

expect_equal(nrow(res), 23)
})


#------------------------------------

test_that("Valores agregados correctos para Artemisia_barrelieri", {

res <- canopy_service_test(mysite_com, mysite_cov)

test_that("Aggregated values correct for Artemisia_barrelieri", {

fila <- res[res$Canopy == "Artemisia_barrelieri", ]

expect_equal(fila$Fc, 18)
expect_equal(fila$Fc, sum(mysite_com[mysite_com$Canopy=="Artemisia_barrelieri" ,"Frequency"]))
expect_equal(fila$Fc, sum(Amoladeras_int[Amoladeras_int$Canopy=="Artemisia_barrelieri" ,"Frequency"]))
expect_equal(fila$Fro, 5111)
expect_equal(fila$Fro, sum(mysite_com[mysite_com$Canopy=="Open" ,"Frequency"]))
expect_equal(fila$Fro, sum(Amoladeras_int[Amoladeras_int$Canopy=="Open" ,"Frequency"]))
Comment on lines 24 to +27
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These assertions are a bit confusing as they test fila$Fc and fila$Fro against both a hardcoded value and a calculated sum. This implicitly tests that the hardcoded value equals the sum. It would be clearer to separate these concerns. You can test the function's output against the hardcoded value, and then have a separate assertion to ensure the input data hasn't changed, i.e., that the sum still equals the hardcoded value.

  expect_equal(fila$Fc, 18)
  expect_equal(sum(Amoladeras_int[Amoladeras_int$Canopy=="Artemisia_barrelieri" ,"Frequency"]), 18)
  expect_equal(fila$Fro, 5111)
  expect_equal(sum(Amoladeras_int[Amoladeras_int$Canopy=="Open" ,"Frequency"]), 5111)

expect_equal(fila$Ac, 1,tolerance = 1e-6)
expect_equal(fila$Ao, 6927,tolerance = 1e-6)

Expand All @@ -53,18 +34,18 @@ test_that("Valores agregados correctos para Artemisia_barrelieri", {

#--------------------------------------

test_that("Clasificación Canopy_effect correcta para especies conocidas", {

res <- canopy_service_test(mysite_com, mysite_cov)

test_that("Clasification Canopy_effect correct for known species", {

expect_equal(
res$Canopy_effect[res$Canopy == "Artemisia_barrelieri"],
"Facilitative"
)

expect_equal(
res$Canopy_effect[res$Canopy == "Artemisia_campestris"],
"Neutral"
)
})