From 41582068696f9b49e20bc7f2072002a955f20f31 Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.fr>
Date: Wed, 4 Aug 2021 15:29:17 +0200
Subject: [PATCH] test(PE_Oudin): add test when TimeStepIn = "hourly" and
 Julian days not ordered Refs #134

---
 tests/testthat/test-evap.R | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/tests/testthat/test-evap.R b/tests/testthat/test-evap.R
index dc2d7bc4..4f655cfc 100644
--- a/tests/testthat/test-evap.R
+++ b/tests/testthat/test-evap.R
@@ -4,6 +4,7 @@ context("Test evaporation")
 rm(list = ls())
 data(L0123001); BasinObs_L0123001 <- BasinObs
 data(L0123002); BasinObs_L0123002 <- BasinObs
+data(L0123003); BasinObs_L0123003 <- BasinObs
 
 comp_evap <- function(BasinObs,
                       Lat, LatUnit,
@@ -65,7 +66,8 @@ test_that("PE_Oudin works", {
 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"
+  msgDaily <- "each day should have only one identical value of julian days. The time series is not sorted, or contains duplicate or missing dates"
+  msgHoury <- "each day must have 24 identical values of julian days (one for each hour). The time series is not sorted, or contains duplicate or missing dates"
 
   # duplicated dates
   DatesFor1Dupl <- BasinObs_L0123001$DatesR
@@ -73,14 +75,22 @@ test_that("Inconsitent time series", {
   expect_warning(object = PE_Oudin(JD = as.POSIXlt(DatesFor1Dupl)$yday + 1,
                                    Temp = BasinObs_L0123001$T,
                                    Lat = 0.8, LatUnit = "rad"),
-                 regexp = warnDaily)
+                 regexp = msgDaily)
 
-  # not ordered dates
+  # not ordered daily 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)
+                 regexp = msgDaily)
+
+  # not ordered hourly dates
+  DatesFor3Messy <- sample(BasinObs_L0123003$DatesR)
+  DatesFor3Messy <- DatesFor3Messy[-5L]
+  expect_error(object = PE_Oudin(JD = as.POSIXlt(DatesFor3Messy)$yday + 1,
+                                   Temp = seq_along(BasinObs_L0123003$T)[-5L],
+                                   Lat = 0.8, LatUnit = "rad", TimeStepIn = "hourly"),
+                 regexp = msgHoury, fixed = TRUE)
 
 
 })
-- 
GitLab