summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/testthat/test_PEC_sw_drift.R31
-rw-r--r--tests/testthat/test_UK_drainage.R36
2 files changed, 61 insertions, 6 deletions
diff --git a/tests/testthat/test_PEC_sw_drift.R b/tests/testthat/test_PEC_sw_drift.R
index 1bcb3d4..da5b185 100644
--- a/tests/testthat/test_PEC_sw_drift.R
+++ b/tests/testthat/test_PEC_sw_drift.R
@@ -35,7 +35,34 @@ test_that("The Rautmann formula is correctly implemented", {
expect_equal(pfm_jki, pfm_rf, tolerance = 0.01)
expect_error(PEC_sw_drift(100, drift_data = "RF", applications = 10), "Only 1 to 8 applications")
- expect_error(PEC_sw_drift(100, drift_data = "RF", applications = 1, crop_group_RF = "Obstbau spaet"),
- "should be one of")
+
+ expect_error(PEC_sw_drift(100, drift_data = "RF", applications = 1, crop_group_RF = "Obstbau spaet"))
expect_silent(PEC_sw_drift(100, drift_data = "RF", applications = 1, crop_group_RF = "fruit, late"))
})
+
+test_that("The function is vectorised also with respect to crop groups", {
+ res_vec_1 <- PEC_sw_drift(
+ rate = rep(100, 6),
+ applications = c(1, 2, rep(1, 4)),
+ water_depth = c(30, 30, 30, 60, 30, 30),
+ crop_group_JKI = c(rep("Ackerbau", 4), rep("Obstbau frueh", 2)),
+ distances = c(rep(5, 4), 10, 5))
+ expect_equal(
+ round(res_vec_1, 3),
+ set_units(c('5 m' = 0.190, '5 m' = 0.157, '5 m' = 0.190, '5 m' = 0.095, '10 m' = 3.937, '5 m' = 6.630), "\u00B5g/L"))
+
+ # Try the same with the Rautmann formula, results are slightly different
+ res_vec_2 <- PEC_sw_drift(
+ rate = rep(100, 6),
+ applications = c(1, 2, rep(1, 4)),
+ water_depth = c(30, 30, 30, 60, 30, 30),
+ drift_data = "RF",
+ crop_group_RF = c(rep("arable", 4), rep("fruit, early", 2)),
+ distances = c(rep(5, 4), 10, 5))
+ expect_equal(
+ round(res_vec_2, 3),
+ set_units(c('5 m' = 0.191, '5 m' = 0.160, '5 m' = 0.191, '5 m' = 0.095, '10 m' = 3.936, '5 m' = 6.628), "\u00B5g/L"))
+
+ # If different argument lengths are supplied, we should get an error
+ expect_error(PEC_sw_drift(c(200, 100), distances = c(1, 5, 10)), "argument lengths")
+})
diff --git a/tests/testthat/test_UK_drainage.R b/tests/testthat/test_UK_drainage.R
index 05c59b2..0286eb4 100644
--- a/tests/testthat/test_UK_drainage.R
+++ b/tests/testthat/test_UK_drainage.R
@@ -1,4 +1,5 @@
library(pfm)
+library(units)
context("UK drainage PEC calculations")
test_that("The mobility classification and the drained percentage are correct", {
@@ -24,15 +25,42 @@ test_that("UK drainflow PECs are correct", {
# 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)
+ expect_equal(round(PEC_sw_drainage_UK(150, interception = 0, Koc = 100), 4),
+ as_units(8.0769, "\u00B5g/L"))
+
+ # Same as above, but using units for the input
+ expect_equal(round(PEC_sw_drainage_UK(as_units(0.15, "kg/ha"), interception = 0,
+ Koc = as_units(100, "mL/g")), 4),
+ as_units(8.0769, "\u00B5g/L"))
# 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)
+ expect_equal(round(PEC_sw_drainage_UK(90, interception = 0, Koc = 10), 4),
+ as_units(13.1538, "\u00B5g/L"))
# 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)
+ latest_application = "01 July",
+ soil_DT50 = 200), 2),
+ as_units(0.84, "\u00B5g/L"))
+
+ # Check and example with early application before the end of the drainage period
+ expect_equal(round(PEC_sw_drainage_UK(90, interception = 0, Koc = 10,
+ latest_application = "01 February",
+ soil_DT50 = 200), 4),
+ as_units(13.1538, "\u00B5g/L"))
+
+ expect_error(round(PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550,
+ latest_application = "100 July",
+ soil_DT50 = 200), 2), "Please specify")
+
+ expect_silent(round(PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550,
+ latest_application = "29 February",
+ soil_DT50 = 200), 2))
+
+ expect_silent(round(PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550,
+ latest_application = "29 February",
+ soil_DT50 = as_units(200, "d")), 2))
+
# Test that PECsw do not increase if the application is after the beginning
# of the drainflow period

Contact - Imprint