diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2016-09-27 23:00:48 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2016-09-27 23:00:48 +0200 |
commit | 12a31f4c130c551f82232d9ef7dfb608bd52c53f (patch) | |
tree | 2525ab1ea4102a6edddbd0c2f03f4a851bf2f9c5 /tests/testthat | |
parent | 0d958ab6f84b569b5437f231c56004890c4ae23b (diff) |
Reorganise repository using standard package layout
Diffstat (limited to 'tests/testthat')
-rw-r--r-- | tests/testthat/EXSW2_R1_stream_printed.txt | 10 | ||||
-rw-r--r-- | tests/testthat/H_sw_D4_pond_printed.txt | 10 | ||||
-rw-r--r-- | tests/testthat/H_sw_R1_stream_events.rds | bin | 0 -> 334 bytes | |||
-rw-r--r-- | tests/testthat/H_sw_R1_stream_printed.txt | 10 | ||||
-rw-r--r-- | tests/testthat/H_sw_R1_stream_windows.rds | bin | 0 -> 235 bytes | |||
-rw-r--r-- | tests/testthat/test_PEC_sed.R | 9 | ||||
-rw-r--r-- | tests/testthat/test_PEC_soil.R | 95 | ||||
-rw-r--r-- | tests/testthat/test_PEC_sw_drift.R | 15 | ||||
-rw-r--r-- | tests/testthat/test_SFO_actual_twa.R | 13 | ||||
-rw-r--r-- | tests/testthat/test_TOXSWA_cwa.R | 56 | ||||
-rw-r--r-- | tests/testthat/test_UK_drainage.R | 33 | ||||
-rw-r--r-- | tests/testthat/test_geomean.R | 11 |
12 files changed, 262 insertions, 0 deletions
diff --git a/tests/testthat/EXSW2_R1_stream_printed.txt b/tests/testthat/EXSW2_R1_stream_printed.txt new file mode 100644 index 0000000..60bb5ac --- /dev/null +++ b/tests/testthat/EXSW2_R1_stream_printed.txt @@ -0,0 +1,10 @@ +<TOXSWA_cwa> data from file 3.out segment 20 + datetime t t_firstjan t_rel_to_max cwa_mug_per_L +1 1978-10-01 00:00:00 0.000 273.0000 -55.083 0 +2 1978-10-01 01:00:00 0.042 273.0417 -55.041 0 +3 1978-10-01 02:00:00 0.083 273.0833 -55.000 0 +4 1978-10-01 03:00:00 0.125 273.1250 -54.958 0 +5 1978-10-01 04:00:00 0.167 273.1667 -54.916 0 +6 1978-10-01 05:00:00 0.208 273.2083 -54.875 0 +Moving window analysis +NULL diff --git a/tests/testthat/H_sw_D4_pond_printed.txt b/tests/testthat/H_sw_D4_pond_printed.txt new file mode 100644 index 0000000..5730be6 --- /dev/null +++ b/tests/testthat/H_sw_D4_pond_printed.txt @@ -0,0 +1,10 @@ +<TOXSWA_cwa> data from file 00001p_pa.cwa segment 1 + datetime t t_firstjan t_rel_to_max cwa_mug_per_L cwa_tot_mug_per_L +1 1985-01-01 00:00:00 0.000 0.00000000 -396.167 0.00000000 0.00000000 +2 1985-01-01 01:00:00 0.042 0.04166667 -396.125 0.08323064 0.08323716 +3 1985-01-01 02:00:00 0.083 0.08333333 -396.084 0.16626900 0.16628210 +4 1985-01-01 03:00:00 0.125 0.12500000 -396.042 0.24911240 0.24913190 +5 1985-01-01 04:00:00 0.167 0.16666667 -396.000 0.33172050 0.33174650 +6 1985-01-01 05:00:00 0.208 0.20833333 -395.959 0.41401430 0.41404670 +Moving window analysis +NULL diff --git a/tests/testthat/H_sw_R1_stream_events.rds b/tests/testthat/H_sw_R1_stream_events.rds Binary files differnew file mode 100644 index 0000000..ba6557b --- /dev/null +++ b/tests/testthat/H_sw_R1_stream_events.rds diff --git a/tests/testthat/H_sw_R1_stream_printed.txt b/tests/testthat/H_sw_R1_stream_printed.txt new file mode 100644 index 0000000..572ad6d --- /dev/null +++ b/tests/testthat/H_sw_R1_stream_printed.txt @@ -0,0 +1,10 @@ +<TOXSWA_cwa> data from file 00003s_pa.cwa segment 20 + datetime t t_firstjan t_rel_to_max cwa_mug_per_L cwa_tot_mug_per_L +20 1978-10-01 00:00:00 0.000 273.0000 -55.333 0 0 +40 1978-10-01 01:00:00 0.042 273.0417 -55.291 0 0 +60 1978-10-01 02:00:00 0.083 273.0833 -55.250 0 0 +80 1978-10-01 03:00:00 0.125 273.1250 -55.208 0 0 +100 1978-10-01 04:00:00 0.167 273.1667 -55.166 0 0 +120 1978-10-01 05:00:00 0.208 273.2083 -55.125 0 0 +Moving window analysis +NULL diff --git a/tests/testthat/H_sw_R1_stream_windows.rds b/tests/testthat/H_sw_R1_stream_windows.rds Binary files differnew file mode 100644 index 0000000..2531189 --- /dev/null +++ b/tests/testthat/H_sw_R1_stream_windows.rds diff --git a/tests/testthat/test_PEC_sed.R b/tests/testthat/test_PEC_sed.R new file mode 100644 index 0000000..443f789 --- /dev/null +++ b/tests/testthat/test_PEC_sed.R @@ -0,0 +1,9 @@ +context("Simple PEC sediment calculations") + +test_that("PEC_sw_sed calculates correctly using the percentage method", { + # Application of 100 g/ha, 1 m spray drift distance (2.77% drift input), 50% in sediment, + # default assumptions of CRD spreadsheet (5 cm sediment depth, 1.3 kg/L sediment density) + # Reference value calculated with CRD spreadsheet + PEC_sw_100_1_m <- PEC_sw_drift(100, distances = 1) + expect_equivalent(round(PEC_sw_sed(PEC_sw_100_1_m, percentage = 50), 3), 2.131) +}) diff --git a/tests/testthat/test_PEC_soil.R b/tests/testthat/test_PEC_soil.R new file mode 100644 index 0000000..0661a52 --- /dev/null +++ b/tests/testthat/test_PEC_soil.R @@ -0,0 +1,95 @@ +library(pfm) +context("Simple PEC soil calculations") + +test_that("PEC_soil calculates correctly", { + # Application of 100 g/ha gives 0.133 mg/kg under default assumptions + expect_equal(as.numeric(PEC_soil(100)), 0.1 * 4/3) + + # or 0.1 mg/kg assuming 25% interception + expect_equal(as.numeric(PEC_soil(100, interception = 0.25)), 0.1) + + # Mixing depth of 1 cm gives five-fold PEC + expect_equal(as.numeric(PEC_soil(100, interception = 0.25, mixing_depth = 1)), 0.5) +}) + +test_that("Tier 1 PEC soil example for Pesticide A in EFSA guidance can be reproduced", { + # Calculate total soil concentrations for tier 1 scenarios + results_pfm <- PEC_soil(1000, interval = 365, DT50 = 250, t_avg = c(0, 21), + scenarios = "EFSA_2015") + + # From Table I.5, p. 80 + results_guidance <- matrix(c(22.0, 11.5, 9.1, 21.8, 11.4, 9.0), + ncol = 3, byrow = TRUE) + dimnames(results_guidance) <- list(t_avg = c(0, 21), + scenario = c("CTN", "CTC", "CTS")) + + + expect_equal(round(results_pfm, 1), results_guidance) + + # Calculate porewater soil concentrations for tier 1 scenarios + results_pfm_pw <- PEC_soil(1000, interval = 365, DT50 = 250, t_av = c(0, 21), + Kom = 1000, scenarios = "EFSA_2015", porewater = TRUE) + + # From Table I.5, p. 80 + results_guidance_pw <- matrix(c(0.76, 0.67, 0.91, 0.75, 0.66, 0.90), + ncol = 3, byrow = TRUE) + dimnames(results_guidance_pw) <- list(t_avg = c(0, 21), + scenario = c("CLN", "CLC", "CLS")) + + expect_equal(round(results_pfm_pw, 2), results_guidance_pw) +}) + +test_that("Tier 1 PEC soil example for Pesticide F in EFSA guidance can be reproduced", { + # Parent F + # Calculate total and porewater soil concentrations for tier 1 scenarios + results_pfm <- PEC_soil(1000, interval = 365, DT50 = 25, t_avg = c(0, 21), + scenarios = "EFSA_2015") + results_pfm_pw <- PEC_soil(1000, interval = 365, DT50 = 25, t_av = c(0, 21), + Kom = 1000, scenarios = "EFSA_2015", porewater = TRUE) + + # From Table I.14, p. 88 + results_guidance <- matrix(c(12.8, 7.7, 6.6, 11.8, 6.8, 5.7), + ncol = 3, byrow = TRUE) + results_guidance_pw <- matrix(c(0.50, 0.46, 0.71, 0.45, 0.41, 0.60), + ncol = 3, byrow = TRUE) + + # Skip checking dimnames by using expect_equivalent() + expect_equivalent(round(results_pfm, 1), results_guidance) + expect_equivalent(round(results_pfm_pw, 2), results_guidance_pw) + + # Metabolite M1 + # Calculate total and porewater soil concentrations for tier 1 scenarios + # Relative molar mass is 200/300, formation fraction is 0.7 + results_pfm <- PEC_soil(200/300 * 0.7 * 1000, interval = 365, DT50 = 100, t_avg = c(0, 21), + scenarios = "EFSA_2015") + results_pfm_pw <- PEC_soil(200/300 * 0.7 * 1000, interval = 365, DT50 = 100, t_av = c(0, 21), + Kom = 10, scenarios = "EFSA_2015", porewater = TRUE) + + # From Table I.15, p. 88 + results_guidance <- matrix(c(7.27, 4.08, 3.38, 7.12, 3.97, 3.26), + ncol = 3, byrow = TRUE) + results_guidance_pw <- matrix(c(12.93, 10.42, 11.66, 12.58, 10.09, 11.15), + ncol = 3, byrow = TRUE) + + # Skip checking dimnames by using expect_equivalent() + expect_equivalent(round(results_pfm, 2), results_guidance) + expect_equivalent(round(results_pfm_pw, 2), results_guidance_pw) + + # Metabolite M2 + # Calculate total and porewater soil concentrations for tier 1 scenarios + # Relative molar mass is 100/300, formation fraction is 0.7 * 1 + results_pfm <- PEC_soil(100/300 * 0.7 * 1 * 1000, interval = 365, DT50 = 250, t_avg = c(0, 21), + scenarios = "EFSA_2015") + results_pfm_pw <- PEC_soil(100/300 * 0.7 * 1000, interval = 365, DT50 = 250, t_av = c(0, 21), + Kom = 100, scenarios = "EFSA_2015", porewater = TRUE) + + # From Table I.16, p. 89 + results_guidance <- matrix(c(5.13, 2.69, 2.13, 5.08, 2.66, 2.10), + ncol = 3, byrow = TRUE) + results_guidance_pw <- matrix(c(1.61, 1.39, 1.80, 1.60, 1.37, 1.77), + ncol = 3, byrow = TRUE) + + # Skip checking dimnames by using expect_equivalent() + expect_equivalent(round(results_pfm, 2), results_guidance) + expect_equivalent(round(results_pfm_pw, 2), results_guidance_pw) +}) diff --git a/tests/testthat/test_PEC_sw_drift.R b/tests/testthat/test_PEC_sw_drift.R new file mode 100644 index 0000000..d09d578 --- /dev/null +++ b/tests/testthat/test_PEC_sw_drift.R @@ -0,0 +1,15 @@ +library(pfm) +context("Simple PEC surface water calculations with drift entry") + +test_that("PEC_sw_drift gives the same results as the CRD PEC calculator", { + # One application of 30 g/ha to field crops calculated with UK PEC calculator published by CRD + expect_equal(round(PEC_sw_drift(30), 3), + c('1 m' = 0.277, '5 m' = 0.057, '10 m' = 0.029, '20 m' = 0.015)) + + # 7 applications of 30 g/ha to field crops calculated with UK PEC calculator, initial PEC + expect_equal(round(PEC_sw_drift(30, 7), 3), + c('1 m' = 0.161, '5 m' = 0.033, '10 m' = 0.017, '20 m' = 0.008)) + + # 4 applications of 30 g/ha to late fruit crops calculated with UK PEC calculator published by CRD (uses different drift values from SANCO aquatic guidance) + #expect_equal(round(PEC_sw_drift(30, 4, crop = "Obstbau spät", distances = c(3, 20, 50)), 3), c('3 m' = 1.101, '20 m' = 0.080, '50 m' = 0.013)) +}) diff --git a/tests/testthat/test_SFO_actual_twa.R b/tests/testthat/test_SFO_actual_twa.R new file mode 100644 index 0000000..b0a5537 --- /dev/null +++ b/tests/testthat/test_SFO_actual_twa.R @@ -0,0 +1,13 @@ +library(pfm) +context("Actual and time weighted average concentrations for SFO kinetics") + +test_that("SFO_actual_twa calculates correctly", { + test_times <- c(0, 1, 7, 21, 42) + # This was calculated with the CRD spreadsheet for multiple applications + reference <- data.frame( + actual = c(10, 9.330, 6.156, 2.333, 0.544), + twa = c(NaN, 9.661, 7.923, 5.267, 3.248), + row.names = test_times) + result <- round(10 * SFO_actual_twa(10, times = test_times), 3) + expect_equal(result, reference) +}) diff --git a/tests/testthat/test_TOXSWA_cwa.R b/tests/testthat/test_TOXSWA_cwa.R new file mode 100644 index 0000000..7c9a73c --- /dev/null +++ b/tests/testthat/test_TOXSWA_cwa.R @@ -0,0 +1,56 @@ +library(pfm) +context("Read and analyse TOXSWA cwa files") + +zipfile_test = system.file("testdata/SwashProjects.zip", package = "pfm") +basedir_test = "SwashProjects/project_H_sw/TOXSWA" + +H_sw_D4_pond <- read.TOXSWA_cwa("00001p_pa.cwa", + basedir = basedir_test, + zipfile = zipfile_test) + +H_sw_R1_stream <- read.TOXSWA_cwa("00003s_pa.cwa", + basedir = basedir_test, + zipfile = zipfile_test) + +basedir_test_2 = "SwashProjects/Project_1/TOXSWA" + +EXSW2_R1_stream <- read.TOXSWA_cwa("3.out", + basedir = basedir_test_2, + zipfile = zipfile_test) + + + +test_that("TOXSWA cwa file is correctly read and printed", { + + # This was the setting when printing the output into text files + options(width = 100) + + # Most content of the R6 object is at least partially printed + + H_sw_D4_pond_printed <- capture.output(print(H_sw_D4_pond)) + + expect_equal(H_sw_D4_pond_printed, readLines("H_sw_D4_pond_printed.txt")) + + H_sw_R1_stream_printed <- capture.output(print(H_sw_R1_stream)) + expect_equal(H_sw_R1_stream_printed, readLines("H_sw_R1_stream_printed.txt")) + + # The basedir is not printed, therefore tested separately + expect_equal(H_sw_D4_pond$basedir, basedir_test) + + EXSW2_R1_stream_printed <- capture.output(print(EXSW2_R1_stream)) + expect_equal(EXSW2_R1_stream_printed, readLines("EXSW2_R1_stream_printed.txt")) + + # The basedir is not printed, therefore tested separately + expect_equal(H_sw_D4_pond$basedir, basedir_test) +}) + +test_that("Getting events and moving window analysis works", { + + # Event analysis with two different thresholds + H_sw_R1_stream$get_events(c(2, 10)) + expect_equal_to_reference(H_sw_R1_stream$events, file = "H_sw_R1_stream_events.rds") + + # Moving window analysis + H_sw_R1_stream$moving_windows(c(7, 21)) + expect_equal_to_reference(H_sw_R1_stream$windows, file = "H_sw_R1_stream_windows.rds") +}) diff --git a/tests/testthat/test_UK_drainage.R b/tests/testthat/test_UK_drainage.R new file mode 100644 index 0000000..859f145 --- /dev/null +++ b/tests/testthat/test_UK_drainage.R @@ -0,0 +1,33 @@ +library(pfm) +context("UK drainage PEC calculations") + +test_that("The mobility classification and the drained percentage are correct", { + # Expected results are from the CRD drainage calculator, retrieved 2015-06-11 + + expect_equivalent(SSLRC_mobility_classification(1), list("Very mobile", 1.9)) + expect_equivalent(SSLRC_mobility_classification(15), list("Mobile", 1.9)) + expect_equivalent(SSLRC_mobility_classification(30), list("Mobile", 1.9)) + expect_equivalent(SSLRC_mobility_classification(74.9), list("Mobile", 1.9)) + expect_equivalent(SSLRC_mobility_classification(75), list("Moderately mobile", 0.7)) + expect_equivalent(SSLRC_mobility_classification(100), list("Moderately mobile", 0.7)) + expect_equivalent(SSLRC_mobility_classification(800), list("Slightly mobile", 0.5)) + expect_equivalent(SSLRC_mobility_classification(2000), list("Slightly mobile", 0.02)) + expect_equivalent(SSLRC_mobility_classification(5000), list("Non mobile", 0.01)) +}) + +test_that("UK drainflow PECs are correct", { + # Expected results are from the CRD drainage calculator, retrieved 2015-06-11, except + # for the third example from the data requirements handbook + + # This is the first example calculation from the data requirements handbook, where they give + # 8.07 µg/L as the result (obviously a rounding error). + expect_equal(round(PEC_sw_drainage_UK(150, interception = 0, Koc = 100), 4), 8.0769) + + # This is the second example calculation from the data requirements handbook + expect_equal(round(PEC_sw_drainage_UK(90, interception = 0, Koc = 10), 4), 13.1538) + + # This is the third example calculation from the data requirements handbook, + expect_equal(round(PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550, + latest_application = "01 July", + soil_DT50 = 200), 2), 0.84) +}) diff --git a/tests/testthat/test_geomean.R b/tests/testthat/test_geomean.R new file mode 100644 index 0000000..0cc3416 --- /dev/null +++ b/tests/testthat/test_geomean.R @@ -0,0 +1,11 @@ +library(pfm) +context("Geometric mean calculation") + +test_that("The geometric mean is correctly calculated", { + expect_equal(geomean(c(1, 3, 9)), 3) + expect_equal(geomean(c(0, 3, 9)), 0) + expect_error(geomean(c(1, 3, NA, 9), na.rm = FALSE), "NA") + expect_equal(geomean(c(1, 3, NA, 9), na.rm = TRUE), 3) + expect_error(geomean(c(1, -3, 9)), "positive") + expect_error(geomean(c(1, -3, NA, 9)), "positive") +}) |