From 2da04b29f339495f7f401d0d14b928a68395e959 Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Mon, 27 May 2024 18:35:33 +0530 Subject: [PATCH 1/9] added test dummies --- .../tests/testthat/test.jagify.R | 33 +++++++++++++++ .../tests/testthat/test.meta.analysis.R | 3 ++ .../tests/testthat/test.run.meta.analysis.R | 41 +++---------------- .../tests/testthat/test.single.MA.R | 5 +++ 4 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 modules/meta.analysis/tests/testthat/test.jagify.R create mode 100644 modules/meta.analysis/tests/testthat/test.meta.analysis.R create mode 100644 modules/meta.analysis/tests/testthat/test.single.MA.R diff --git a/modules/meta.analysis/tests/testthat/test.jagify.R b/modules/meta.analysis/tests/testthat/test.jagify.R new file mode 100644 index 00000000000..7d934c10113 --- /dev/null +++ b/modules/meta.analysis/tests/testthat/test.jagify.R @@ -0,0 +1,33 @@ +#------------------------------------------------------------------------------- +# Copyright (c) 2012 University of Illinois, NCSA. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the +# University of Illinois/NCSA Open Source License +# which accompanies this distribution, and is available at +# http://opensource.ncsa.illinois.edu/license.html +#------------------------------------------------------------------------------- + +test_that("jagify correctly assigns treatment index of 1 to all control treatments, regardless of alphabetical order", { + ## generate test data; controls assigned to early alphabet and late alphabet trt names + testresult <- data.frame(citation_id = 1, + site_id = rep(1:2, each = 5), + name = rep(letters[1:5],2), + trt_id = as.character(rep(letters[1:5],2)), + control = c(1, rep(0,8), 1), + greenhouse = c(rep(0,5), rep(1,5)), + date = 1, + time = NA, + cultivar_id = 1, + specie_id = 1, + n = 2, + mean = sqrt(1:10), + stat = 1, + statname = "SE", + treatment_id = 1:10 + ) + i <- sapply(testresult, is.factor) + testresult[i] <- lapply(testresult[i], as.character) + + jagged.data <- jagify(testresult) + expect_equal(jagged.data$trt_num[jagged.data$trt == "control"], c(1, 1)) +}) diff --git a/modules/meta.analysis/tests/testthat/test.meta.analysis.R b/modules/meta.analysis/tests/testthat/test.meta.analysis.R new file mode 100644 index 00000000000..87841bea8ca --- /dev/null +++ b/modules/meta.analysis/tests/testthat/test.meta.analysis.R @@ -0,0 +1,3 @@ +test_that("`pecan.ma`", { + +}) \ No newline at end of file diff --git a/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R b/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R index f777fdbd7e8..23837003cd5 100644 --- a/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R +++ b/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R @@ -1,42 +1,11 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2012 University of Illinois, NCSA. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the -# University of Illinois/NCSA Open Source License -# which accompanies this distribution, and is available at -# http://opensource.ncsa.illinois.edu/license.html -#------------------------------------------------------------------------------- +test_that("`runModule.run.meta.analysis`", { -context("run.meta.analysis") +}) +test_that("`run.meta.analysis`", { -test_that("singleMA gives expected result for example inputs",{ - ## need to calculate x - ## x <- singleMA(....) - #expect_equal(round(summary(x)$statistics["beta.o", "Mean"]), 5) }) -test_that("jagify correctly assigns treatment index of 1 to all control treatments, regardless of alphabetical order", { - ## generate test data; controls assigned to early alphabet and late alphabet trt names - testresult <- data.frame(citation_id = 1, - site_id = rep(1:2, each = 5), - name = rep(letters[1:5],2), - trt_id = as.character(rep(letters[1:5],2)), - control = c(1, rep(0,8), 1), - greenhouse = c(rep(0,5), rep(1,5)), - date = 1, - time = NA, - cultivar_id = 1, - specie_id = 1, - n = 2, - mean = sqrt(1:10), - stat = 1, - statname = "SE", - treatment_id = 1:10 - ) - i <- sapply(testresult, is.factor) - testresult[i] <- lapply(testresult[i], as.character) +test_that("`run.meta.analysis.pft`", { - jagged.data <- jagify(testresult) - expect_equal(jagged.data$trt_num[jagged.data$trt == "control"], c(1, 1)) -}) +}) \ No newline at end of file diff --git a/modules/meta.analysis/tests/testthat/test.single.MA.R b/modules/meta.analysis/tests/testthat/test.single.MA.R new file mode 100644 index 00000000000..c24c9c0d2aa --- /dev/null +++ b/modules/meta.analysis/tests/testthat/test.single.MA.R @@ -0,0 +1,5 @@ +test_that("`single.MA` gives expected result for example inputs", { + ## need to calculate x + ## x <- singleMA(....) + #expect_equal(round(summary(x)$statistics["beta.o", "Mean"]), 5) +}) From 84739bf37d8f9138a5e1e1f06c310a24195412bc Mon Sep 17 00:00:00 2001 From: Meet Agrawal Date: Sun, 9 Jun 2024 17:32:26 +0530 Subject: [PATCH 2/9] fixed test --- modules/meta.analysis/tests/testthat/test.jagify.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/meta.analysis/tests/testthat/test.jagify.R b/modules/meta.analysis/tests/testthat/test.jagify.R index 7d934c10113..7541783f18b 100644 --- a/modules/meta.analysis/tests/testthat/test.jagify.R +++ b/modules/meta.analysis/tests/testthat/test.jagify.R @@ -25,9 +25,7 @@ test_that("jagify correctly assigns treatment index of 1 to all control treatmen statname = "SE", treatment_id = 1:10 ) - i <- sapply(testresult, is.factor) - testresult[i] <- lapply(testresult[i], as.character) jagged.data <- jagify(testresult) - expect_equal(jagged.data$trt_num[jagged.data$trt == "control"], c(1, 1)) + expect_equal(jagged.data$trt_num[jagged.data$trt == "control"], c(1, 1)) }) From 1a0594c929536a7eb958d85f057b82b9258cc06f Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Sat, 6 Jul 2024 18:29:36 +0530 Subject: [PATCH 3/9] added tests : runModule.run.meta.analysis, run.meta.analysis --- .../tests/testthat/test.run.meta.analysis.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R b/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R index 23837003cd5..46d02343efb 100644 --- a/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R +++ b/modules/meta.analysis/tests/testthat/test.run.meta.analysis.R @@ -1,11 +1,20 @@ -test_that("`runModule.run.meta.analysis`", { - +test_that("`runModule.run.meta.analysis` throws an error for incorrect input", { + expect_error(runModule.run.meta.analysis('test'), "only works with Settings or MultiSettings") }) -test_that("`run.meta.analysis`", { - +test_that("`run.meta.analysis` able to call run.meta.analysis.pft for each pft in the input list", { + mocked_res <- mockery::mock(1, cycle = TRUE) + mockery::stub(run.meta.analysis, 'run.meta.analysis.pft', mocked_res) + mockery::stub(run.meta.analysis, 'PEcAn.DB::db.open', 1) + mockery::stub(run.meta.analysis, 'PEcAn.DB::db.close', 1) + pfts <- list('ebifarm.salix', 'temperate.coniferous') + run.meta.analysis(pfts = pfts, iterations = 1, dbfiles = NULL, database = NULL) + mockery::expect_called(mocked_res, 2) + args <- mockery::mock_args(mocked_res) + expect_equal(args[[1]][[1]], "ebifarm.salix") + expect_equal(args[[2]][[1]], "temperate.coniferous") }) test_that("`run.meta.analysis.pft`", { - + }) \ No newline at end of file From 3c0d9b7b8249cfff9f1a1963d3c31dee23cf4c37 Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Sun, 7 Jul 2024 11:12:21 +0530 Subject: [PATCH 4/9] added mockery to desc --- modules/meta.analysis/DESCRIPTION | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/meta.analysis/DESCRIPTION b/modules/meta.analysis/DESCRIPTION index 1cd66a9fe56..28cbe7681d7 100644 --- a/modules/meta.analysis/DESCRIPTION +++ b/modules/meta.analysis/DESCRIPTION @@ -28,16 +28,17 @@ Description: The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific Imports: coda (>= 0.18), lattice, - PEcAn.utils, + MASS, PEcAn.DB, PEcAn.logger, - MASS, PEcAn.settings, + PEcAn.utils, rjags Suggests: ggmcmc, ggplot2, knitr (>= 1.42), + mockery, rmarkdown (>= 2.19), testthat (>= 1.0.2) SystemRequirements: JAGS From f7e9846aa11c53bc462bfad00d20670ba0cb02ec Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Sun, 7 Jul 2024 11:16:42 +0530 Subject: [PATCH 5/9] bug fix --- docker/depends/pecan_package_dependencies.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/depends/pecan_package_dependencies.csv b/docker/depends/pecan_package_dependencies.csv index 72846487865..b11ef517001 100644 --- a/docker/depends/pecan_package_dependencies.csv +++ b/docker/depends/pecan_package_dependencies.csv @@ -196,6 +196,7 @@ "mockery","*","base/visualization","Suggests",FALSE "mockery","*","base/workflow","Suggests",FALSE "mockery","*","modules/data.atmosphere","Suggests",FALSE +"mockery","*","modules/meta.analysis","Suggests",FALSE "mockery",">= 0.3.0","models/biocro","Suggests",FALSE "mockery",">= 0.4.3","base/db","Suggests",FALSE "MODISTools",">= 1.1.0","modules/data.remote","Imports",FALSE From e79be90cf2967c5cdcaecce1e6d1c0745d78bce5 Mon Sep 17 00:00:00 2001 From: meetagrawal09 Date: Sun, 7 Jul 2024 16:32:56 +0530 Subject: [PATCH 6/9] added final tests, fixed some typos --- .../03_topical_pages/94_docker/04_models.Rmd | 2 +- modules/meta.analysis/R/meta.analysis.R | 2 +- modules/meta.analysis/R/run.meta.analysis.R | 2 +- modules/meta.analysis/man/pecan.ma.Rd | 2 +- modules/meta.analysis/man/run.meta.analysis.Rd | 2 +- .../tests/testthat/test.meta.analysis.R | 3 --- .../tests/testthat/test.run.meta.analysis.R | 17 +++++++++++++++-- .../tests/testthat/test.single.MA.R | 5 ----- 8 files changed, 20 insertions(+), 15 deletions(-) delete mode 100644 modules/meta.analysis/tests/testthat/test.meta.analysis.R delete mode 100644 modules/meta.analysis/tests/testthat/test.single.MA.R diff --git a/book_source/03_topical_pages/94_docker/04_models.Rmd b/book_source/03_topical_pages/94_docker/04_models.Rmd index 205098b4593..8054671922e 100644 --- a/book_source/03_topical_pages/94_docker/04_models.Rmd +++ b/book_source/03_topical_pages/94_docker/04_models.Rmd @@ -55,7 +55,7 @@ It is important values for `type` and `version` are set correct. The PEcAn code To build the docker image, we use a Dockerfile (see example below) and run the following command. This command will expect the Dockerfile to live in the model specific folder and the command is executed in the root pecan folder. It will copy the content of the pecan folder and make it available to the build process (in this example we do not need any additional files). -Since we can have multiple different versions of a model be available for PEcAn we ar using the following naming schema `pecan/model--:-: Date: Sat, 27 Jul 2024 18:35:27 +0530 Subject: [PATCH 7/9] fixed typo --- modules/meta.analysis/R/rename_jags_columns.R | 2 +- modules/meta.analysis/man/rename_jags_columns.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/meta.analysis/R/rename_jags_columns.R b/modules/meta.analysis/R/rename_jags_columns.R index d18fc5bb453..43d22ef7b0e 100644 --- a/modules/meta.analysis/R/rename_jags_columns.R +++ b/modules/meta.analysis/R/rename_jags_columns.R @@ -8,7 +8,7 @@ #------------------------------------------------------------------------------- ##-----------------------------------------------------------------------------# -##' renames the variables within output data frame trait.data +##' Renames the variables within output data frame trait.data ##' ##' @param data data frame to with variables to rename ##' diff --git a/modules/meta.analysis/man/rename_jags_columns.Rd b/modules/meta.analysis/man/rename_jags_columns.Rd index 5a53963c293..d9da830d917 100644 --- a/modules/meta.analysis/man/rename_jags_columns.Rd +++ b/modules/meta.analysis/man/rename_jags_columns.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/rename_jags_columns.R \name{rename_jags_columns} \alias{rename_jags_columns} -\title{renames the variables within output data frame trait.data} +\title{Renames the variables within output data frame trait.data} \usage{ rename_jags_columns(data) } From 51f0283b88f35cdce98bfe6b37b0d6bb7b28a118 Mon Sep 17 00:00:00 2001 From: Meet Agrawal Date: Sat, 27 Jul 2024 21:33:47 +0530 Subject: [PATCH 8/9] roxygenise --- modules/meta.analysis/man/rename_jags_columns.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/meta.analysis/man/rename_jags_columns.Rd b/modules/meta.analysis/man/rename_jags_columns.Rd index d9da830d917..7172345230f 100644 --- a/modules/meta.analysis/man/rename_jags_columns.Rd +++ b/modules/meta.analysis/man/rename_jags_columns.Rd @@ -10,7 +10,7 @@ rename_jags_columns(data) \item{data}{data frame to with variables to rename} } \description{ -renames the variables within output data frame trait.data +Renames the variables within output data frame trait.data } \seealso{ used with \code{\link[PEcAn.MA]{jagify}}; From 59140ce8cd53b853f36c28c3f5ddc057fb04165e Mon Sep 17 00:00:00 2001 From: Chris Black Date: Thu, 1 Aug 2024 15:36:05 -0700 Subject: [PATCH 9/9] Update modules/meta.analysis/tests/testthat/test.jagify.R --- modules/meta.analysis/tests/testthat/test.jagify.R | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/meta.analysis/tests/testthat/test.jagify.R b/modules/meta.analysis/tests/testthat/test.jagify.R index 7541783f18b..50949a7a5d7 100644 --- a/modules/meta.analysis/tests/testthat/test.jagify.R +++ b/modules/meta.analysis/tests/testthat/test.jagify.R @@ -1,11 +1,3 @@ -#------------------------------------------------------------------------------- -# Copyright (c) 2012 University of Illinois, NCSA. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the -# University of Illinois/NCSA Open Source License -# which accompanies this distribution, and is available at -# http://opensource.ncsa.illinois.edu/license.html -#------------------------------------------------------------------------------- test_that("jagify correctly assigns treatment index of 1 to all control treatments, regardless of alphabetical order", { ## generate test data; controls assigned to early alphabet and late alphabet trt names