context("Without 'Temp' and 'HypsoData'") # -------- # Loading example data from airGR package data(L0123001, package = "airGR") # Preparing time series inputs input_bd_cn0 <- list( Name = BasinInfo$BasinName, startDate = BasinObs$DatesR[1L], endDate = BasinObs$DatesR[length(BasinObs$DatesR)], P = BasinObs$P, PET = BasinObs$E, Qobs = BasinObs$Qmm ) # Defining BasinData object bd_gr4j <- BasinData(Name = input_bd_cn0$Name, startDate = input_bd_cn0$startDate, endDate = input_bd_cn0$endDate, P = input_bd_cn0$P, PET = input_bd_cn0$PET, Qobs = input_bd_cn0$Qobs, fill = "GR4J") # Creating BaseflowFilter object bf_gr4j_1 <- BaseflowFilter(BasinData = bd_gr4j, alpha = 1000, updateFunction = "quadr") # Computing baseflow bf_gr4j_2 <- perform_filtering(filter = bf_gr4j_1) # Plotting computed separation plot(bf_gr4j_2) # -------- test_that("'BasinData' S4 class", { expect_s4_class( object = bd_gr4j, class = "BasinData" ) }) test_that("'BaseflowFilter' S4 class", { expect_s4_class( object = bf_gr4j_1, class = "BaseflowFilter" ) }) test_that("'BaseflowFilter' S4 class", { expect_s4_class( object = bf_gr4j_2, class = "BaseflowFilter" ) }) # -------- sapply(names(input_bd_cn0), function(i_name) { test_that("'BasinData' input (class)", { input_bd_cn0[[i_name]] <- list(1, 2) expect_error( object = BasinData(Name = input_bd_cn0$Name, startDate = input_bd_cn0$startDate, endDate = input_bd_cn0$endDate, P = input_bd_cn0$P, PET = input_bd_cn0$PET, Qobs = input_bd_cn0$Qobs, fill = "GR4J"), ) }) }) # ---- sapply(names(input_bd_cn0), function(i_name) { test_that("'BasinData' input (length)", { input_bd_cn0[[i_name]] <- 1L expect_error( object = BasinData(Name = input_bd_cn0$Name, startDate = input_bd_cn0$startDate, endDate = input_bd_cn0$endDate, P = input_bd_cn0$P, PET = input_bd_cn0$PET, Qobs = input_bd_cn0$Qobs, fill = "GR4J"), ) }) }) # ---- sapply(names(input_bd_cn0), function(i_name) { test_that("'BasinData' input (missing value)", { input_bd_cn0[[i_name]] <- NA expect_error( object = BasinData(Name = input_bd_cn0$Name, startDate = input_bd_cn0$startDate, endDate = input_bd_cn0$endDate, P = input_bd_cn0$P, PET = input_bd_cn0$PET, Qobs = input_bd_cn0$Qobs, fill = "GR4J"), ) }) }) # -------- test_that("'BaseflowFilter' input (class)", { expect_error( BaseflowFilter(BasinData = 1L, alpha = 1000, updateFunction = "quadr"), ) }) # ---- test_that("'BaseflowFilter' input (class)", { expect_error( BaseflowFilter(BasinData = bd_gr4j, alpha = "1000", updateFunction = "quadr"), ) }) # -------- test_that("'bf_gr4j_1' input (class)", { expect_error( perform_filtering(1L), ) }) # -------- test_that("'corr_crit' input (length)", { expect_error( corr_crit(BasinData = bd_gr4j, alpha = 1500:1501, tau = 110, updateFunction = "quadr"), ) }) # ---- test_that("'corr_crit' input (length)", { expect_error( corr_crit(BasinData = bd_gr4j, alpha = 1500, tau = 110:111, updateFunction = "quadr"), ) }) # -------- test_that("'bfi' input (class)", { expect_error( bfi(filter = 1L), ) }) # ---------------- context("Witht 'Temp' and 'HypsoData'") # -------- # Loading example data from airGR package data(L0123002, package = "airGR") BasinObs$Qmm[10000:10593] <- NA # Preparing time series inputs input_bd_cn1 <- list( Name = BasinInfo$BasinName, startDate = BasinObs$DatesR[1L], endDate = BasinObs$DatesR[length(BasinObs$DatesR)], P = BasinObs$P, PET = BasinObs$E, Qobs = BasinObs$Qmm, Temp = BasinObs$T, HypsoData = BasinInfo$HypsoData ) # Defining BasinData object with GR4J and Temp & HypsoData values bd_gr4j_cn0 <- BasinData(Name = input_bd_cn1$Name, startDate = input_bd_cn1$startDate, endDate = input_bd_cn1$endDate, P = input_bd_cn1$P, PET = input_bd_cn1$PET, Qobs = input_bd_cn1$Qobs, Temp = input_bd_cn1$Temp, HypsoData = rep(0, 101),#input_bd_cn1$HypsoData, fill = "GR4J") # Defining BasinData object with CemaNeigeGR4J and stupid Temp & HypsoData values bd_gr4j_cn1a <- BasinData(Name = input_bd_cn1$Name, startDate = input_bd_cn1$startDate, endDate = input_bd_cn1$endDate, P = input_bd_cn1$P, PET = input_bd_cn1$PET, Qobs = input_bd_cn1$Qobs, Temp = input_bd_cn1$Temp, HypsoData = rep(0, 101), fill = "CemaNeigeGR4J") # Defining BasinData object with CemaNeigeGR4J and normal Temp & HypsoData values bd_gr4j_cn1b <- BasinData(Name = input_bd_cn1$Name, startDate = input_bd_cn1$startDate, endDate = input_bd_cn1$endDate, P = input_bd_cn1$P, PET = input_bd_cn1$PET, Qobs = input_bd_cn1$Qobs, Temp = input_bd_cn1$Temp, HypsoData = input_bd_cn1$HypsoData, fill = "CemaNeigeGR4J") # -------- test_that("Missing 'HypsoData' input in 'BasinData' when using 'CemaNeigeGR4J'", { expect_warning( BasinData(Name = input_bd_cn1$Name, startDate = input_bd_cn1$startDate, endDate = input_bd_cn1$endDate, P = input_bd_cn1$P, PET = input_bd_cn1$PET, Qobs = input_bd_cn1$Qobs, Temp = input_bd_cn1$Temp, HypsoData = NULL, fill = "CemaNeigeGR4J"), regexp = "'HypsoData' is missing" ) }) test_that("Missing 'Temp' input in 'BasinData' when using 'CemaNeigeGR4J'", { expect_error( BasinData(Name = input_bd_cn1$Name, startDate = input_bd_cn1$startDate, endDate = input_bd_cn1$endDate, P = input_bd_cn1$P, PET = input_bd_cn1$PET, Qobs = input_bd_cn1$Qobs, Temp = NULL, HypsoData = rep(0, 101), fill = "CemaNeigeGR4J") ) }) # Creating BaseflowFilter object bf_cn0_1 <- BaseflowFilter(BasinData = bd_gr4j_cn0, alpha = 1000, updateFunction = "quadr") bf_cn1_1a <- BaseflowFilter(BasinData = bd_gr4j_cn1a, alpha = 1000, updateFunction = "quadr") bf_cn1_1b <- BaseflowFilter(BasinData = bd_gr4j_cn1b, alpha = 1000, updateFunction = "quadr") # Computing baseflow bf_cn0_2 <- perform_filtering(filter = bf_cn0_1) bf_cn1_2a <- perform_filtering(filter = bf_cn1_1a) bf_cn1_2b <- perform_filtering(filter = bf_cn1_1b) # Plotting computed separation plot(bf_cn0_2) plot(bf_cn1_2a) plot(bf_cn1_2b) # -------- test_that("'BasinData' S4 class", { expect_s4_class( object = bd_gr4j_cn0, class = "BasinData" ) }) test_that("'BasinData' S4 class", { expect_s4_class( object = bd_gr4j_cn1a, class = "BasinData" ) }) test_that("'BasinData' S4 class", { expect_s4_class( object = bd_gr4j_cn1b, class = "BasinData" ) }) # -------- test_that("'HypsoData' with or without 'CemaNeigeGR4J'", { sapply(1:101, function(i) { expect_true( object = bd_gr4j_cn0@HypsoData[i] != bd_gr4j_cn1b@HypsoData[i] ) }) }) # -------- test_that("'BaseflowFilter' return 'R'", { expect_true( object = all(is.na(bf_cn0_1@R)) != all(is.na(bf_cn0_2@R)) ) }) test_that("'BaseflowFilter' return 'R'", { expect_true( object = all(is.na(bf_cn1_1a@R)) != all(is.na(bf_cn1_2a@R)) ) }) test_that("'BaseflowFilter' return 'R'", { expect_true( object = all(is.na(bf_cn1_1b@R)) != all(is.na(bf_cn1_2b@R)) ) }) # -------- test_that("'BaseflowFilter' return 'V'", { expect_true( object = all(is.na(bf_cn0_1@V)) != all(is.na(bf_cn0_2@V)) ) }) test_that("'BaseflowFilter' return 'V'", { expect_true( object = all(is.na(bf_cn1_1a@V)) != all(is.na(bf_cn1_2a@V)) ) }) test_that("'BaseflowFilter' return 'V'", { expect_true( object = all(is.na(bf_cn1_1b@V)) != all(is.na(bf_cn1_2b@V)) ) }) # --------