From 24328f0fabc1982db01132bafb4dc65dd85b13e9 Mon Sep 17 00:00:00 2001 From: Ranke Johannes Date: Fri, 13 Feb 2026 16:13:46 +0100 Subject: Fix UK drainage for very early applications Create a function `drainage_date_UK` that does not only respect the beginning of the drainage period on 1 October, but also the end of the drainage period on 30 April, and use it for determining the degradation time. Applications early in the year before 1 May will now correctly be calculated without degradation time. --- tests/testthat/test_UK_drainage.R | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/testthat') diff --git a/tests/testthat/test_UK_drainage.R b/tests/testthat/test_UK_drainage.R index 75d9c98..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", { @@ -41,6 +42,12 @@ test_that("UK drainflow PECs are correct", { 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", -- cgit v1.2.3