From 488e9a40898637deaed0070501cd84888baf7489 Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.fr> Date: Wed, 4 Aug 2021 14:57:42 +0200 Subject: [PATCH] test(PE_oudin): add test on Julian days Refs #134 --- tests/testthat/test-evap.R | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-evap.R b/tests/testthat/test-evap.R index e68a4715..dc2d7bc4 100644 --- a/tests/testthat/test-evap.R +++ b/tests/testthat/test-evap.R @@ -1,5 +1,10 @@ context("Test evaporation") + +rm(list = ls()) +data(L0123001); BasinObs_L0123001 <- BasinObs +data(L0123002); BasinObs_L0123002 <- BasinObs + comp_evap <- function(BasinObs, Lat, LatUnit, TimeStepIn = "daily", @@ -16,12 +21,9 @@ comp_evap <- function(BasinObs, all(range(PotEvap - PotEvapFor) < 0.000001) } + test_that("PE_Oudin works", { skip_on_cran() - rm(list = ls()) - - data(L0123001); BasinObs_L0123001 <- BasinObs - data(L0123002); BasinObs_L0123002 <- BasinObs expect_true(comp_evap(BasinObs = BasinObs_L0123001, Lat = 0.8, LatUnit = "rad", @@ -59,3 +61,28 @@ test_that("PE_Oudin works", { expect_equal(PotEvapFor, c(PotEvapFor1, PotEvapFor2)) }) + +test_that("Inconsitent time series", { + skip_on_cran() + + warnDaily <- "each day should have only one identical value of julian days. The time series is not sorted, or contains duplicate or missing dates" + + # duplicated dates + DatesFor1Dupl <- BasinObs_L0123001$DatesR + DatesFor1Dupl[5L] <- DatesFor1Dupl[4L] + expect_warning(object = PE_Oudin(JD = as.POSIXlt(DatesFor1Dupl)$yday + 1, + Temp = BasinObs_L0123001$T, + Lat = 0.8, LatUnit = "rad"), + regexp = warnDaily) + + # not ordered dates + DatesFor1Messy <- sample(BasinObs_L0123001$DatesR) + expect_warning(object = PE_Oudin(JD = as.POSIXlt(DatesFor1Messy)$yday + 1, + Temp = BasinObs_L0123001$T, + Lat = 0.8, LatUnit = "rad"), + regexp = warnDaily) + + +}) + + -- GitLab