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.R44
-rw-r--r--tests/testthat/test_exposit.R13
3 files changed, 78 insertions, 10 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 2789819..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,13 +25,48 @@ 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
+ expect_equal(
+ PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550),
+ PEC_sw_drainage_UK(60, interception = 0.5, Koc = 550,
+ latest_application = "01 November", soil_DT50 = 200))
+
})
diff --git a/tests/testthat/test_exposit.R b/tests/testthat/test_exposit.R
index 44337bd..8725815 100644
--- a/tests/testthat/test_exposit.R
+++ b/tests/testthat/test_exposit.R
@@ -62,28 +62,33 @@ test_that("Runoff PECsw are as in Exposit 3.02", {
test_that("Drainage PECsw are as in Exposit 3.02", {
# 100 g/ha, Koc = 1000 L/kg, DT50 = 1000 days
- res_exposit_1 <- c(spring = 0.02, autumn = 0.05)
+ res_exposit_1 <- set_units(c(spring = 0.02, autumn = 0.05),
+ "\u00B5g/L")
res_1 <- PEC_sw_exposit_drainage(100, Koc = 1000, DT50 = 1000)
res_pfm_1 <- round(res_1$PEC_sw_drainage, 2)
expect_equivalent(res_exposit_1, res_pfm_1)
# 10 g/ha, Koc = 300000 L/kg, DT50 = 10 days
- res_exposit_2 <- c(spring = 0.00, autumn = 0.00)
+ res_exposit_2 <- set_units(c(spring = 0.00, autumn = 0.00),
+ "\u00B5g/L")
res_2 <- PEC_sw_exposit_drainage(10, Koc = 300000, DT50 = 10)
res_pfm_2 <- round(res_2$PEC_sw_drainage, 2)
expect_equivalent(res_exposit_2, res_pfm_2)
# 200 g/ha, Koc = 30 L/kg, DT50 = 100 days
- res_exposit_3 <- c(spring = 0.61, autumn = 1.88)
+ res_exposit_3 <- set_units(c(spring = 0.61, autumn = 1.88),
+ "\u00B5g/L")
+
res_3 <- PEC_sw_exposit_drainage(200, Koc = 30, DT50 = 100)
res_pfm_3 <- round(res_3$PEC_sw_drainage, 2)
expect_equivalent(res_exposit_3, res_pfm_3)
# 1000 g/ha, Koc = 545 L/kg, group = 1, DT50 = 20 days, 25% interception
- res_exposit_4 <- c(spring = 0.11, autumn = 0.32)
+ res_exposit_4 <- set_units(c(spring = 0.11, autumn = 0.32),
+ "\u00B5g/L")
res_4 <- PEC_sw_exposit_drainage(1000, interception = 0.25, Koc = 545, DT50 =
20, mobility = "low")

Contact - Imprint