From 55f7f714faca6940331cc69d153409c477884e80 Mon Sep 17 00:00:00 2001 From: aliciamontesinos <40610362+aliciamontesinos@users.noreply.github.com> Date: Thu, 19 Feb 2026 17:58:28 +0100 Subject: [PATCH 1/2] Update test-canopy_service_test.R --- tests/testthat/test-canopy_service_test.R | 50 ++++++++--------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/tests/testthat/test-canopy_service_test.R b/tests/testthat/test-canopy_service_test.R index ab257dd..abda4bc 100644 --- a/tests/testthat/test-canopy_service_test.R +++ b/tests/testthat/test-canopy_service_test.R @@ -1,49 +1,32 @@ -################################################# -#Tests para canopy_service_test -################################################# -#library(testthat) +test_that("canopy_service_test data.frame with correct columns", { -#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") + res <- canopy_service_test(Amoladeras_int, Amoladeras_cover) -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", { + + res <- canopy_service_test(Amoladeras_int, Amoladeras_cover) + 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"])) expect_equal(fila$Ac, 1,tolerance = 1e-6) expect_equal(fila$Ao, 6927,tolerance = 1e-6) @@ -53,18 +36,19 @@ 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", { + + res <- canopy_service_test(Amoladeras_int, Amoladeras_cover) + expect_equal( res$Canopy_effect[res$Canopy == "Artemisia_barrelieri"], "Facilitative" ) - + expect_equal( res$Canopy_effect[res$Canopy == "Artemisia_campestris"], "Neutral" ) }) + From 9f4a4568392de2f1cfdd36f181a47c6a3357b723 Mon Sep 17 00:00:00 2001 From: Francisco Rodriguez-Sanchez Date: Thu, 19 Feb 2026 18:33:42 +0100 Subject: [PATCH 2/2] Refactor tests for canopy_service_test function --- tests/testthat/test-canopy_service_test.R | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-canopy_service_test.R b/tests/testthat/test-canopy_service_test.R index abda4bc..c271959 100644 --- a/tests/testthat/test-canopy_service_test.R +++ b/tests/testthat/test-canopy_service_test.R @@ -1,7 +1,7 @@ -test_that("canopy_service_test data.frame with correct columns", { +res <- canopy_service_test(Amoladeras_int, Amoladeras_cover) - res <- canopy_service_test(Amoladeras_int, Amoladeras_cover) +test_that("canopy_service_test data.frame with correct columns", { expect_s3_class(res, "data.frame") @@ -19,8 +19,6 @@ test_that("canopy_service_test data.frame with correct columns", { test_that("Aggregated values correct for Artemisia_barrelieri", { - res <- canopy_service_test(Amoladeras_int, Amoladeras_cover) - fila <- res[res$Canopy == "Artemisia_barrelieri", ] expect_equal(fila$Fc, 18) @@ -38,8 +36,6 @@ test_that("Aggregated values correct for Artemisia_barrelieri", { test_that("Clasification Canopy_effect correct for known species", { - res <- canopy_service_test(Amoladeras_int, Amoladeras_cover) - expect_equal( res$Canopy_effect[res$Canopy == "Artemisia_barrelieri"], "Facilitative" @@ -52,3 +48,4 @@ test_that("Clasification Canopy_effect correct for known species", { }) +