From e6bb9654679f43af6958d6e28cb5206abb91d574 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Mon, 30 Jan 2017 16:10:30 +0100 Subject: Test reproducing the FOCUS Summary information generated from the FOCUS PELMO GUI, as copied into the text files in the testdata directory. --- tests/testthat/test_PELMO.R | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/testthat/test_PELMO.R b/tests/testthat/test_PELMO.R index a08f607..9bebc95 100644 --- a/tests/testthat/test_PELMO.R +++ b/tests/testthat/test_PELMO.R @@ -85,8 +85,9 @@ test_that("PELMO runs can be run and give the expected result files", { } }) +pfm_PECgw <- evaluate_PELMO(runs) + test_that("PELMO runs are correctly evaluated", { - results <- evaluate_PELMO(runs) # Check that if output is the same as in the test archive for (run in runs) { @@ -142,3 +143,36 @@ test_that("PELMO runs are correctly evaluated", { } } }) + +test_that("PECgw from FOCUS summary files can be reproduced", { + focus_summary <- list() + + for (run in runs) { + psm <- run$psm + focus_summary[[psm]] <- list() + + crops <- setdiff(names(run), "psm") + for (crop in crops) { + scenarios <- run[[crop]] + + # Read contents of summary text file copied from the GUI output. We only + # have results for one crop per psm file, so the crop is not in the file + # name. + sumfile_path <- system.file(paste0("testdata/FOCUS_Summary_", psm, + ".txt"), package = "pfm") + sumfile <- readLines(sumfile_path, encoding = "latin1") + result_anchors <- grep("Results for", sumfile) + acronyms <- gsub(".*\\((.*)\\).*", "\\1", sumfile[result_anchors]) + names(result_anchors) <- acronyms + focus_summary[[psm]][[crop]] <- matrix(nrow = length(scenarios), ncol = length(acronyms), + dimnames = list(scenarios, acronyms)) + for (acronym in acronyms) { + tmp <- sumfile[result_anchors[acronym] + 4 + (1:length(scenarios))] + tmp_frame <- read.table(text = tmp, sep = "\t") + PECgw <- tmp_frame$V5 + focus_summary[[psm]][[crop]][, acronym] <- PECgw + } + } + } + expect_equal(pfm_PECgw, focus_summary) +}) -- cgit v1.2.1