From 42c9fa8de588ec29b69d9dba6ee4c39da66ae813 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Wed, 5 Jul 2023 21:53:45 +0100 Subject: [PATCH 1/2] testthat additions --- tests/testthat/test-annual_rainfall_summaries.R | 8 ++++++-- tests/testthat/test-crop_success_probabilities.R | 12 +++++++++--- tests/testthat/test-total_temperature_summaries.R | 6 +++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-annual_rainfall_summaries.R b/tests/testthat/test-annual_rainfall_summaries.R index abbd33f..3402efb 100644 --- a/tests/testthat/test-annual_rainfall_summaries.R +++ b/tests/testthat/test-annual_rainfall_summaries.R @@ -7,6 +7,10 @@ # summaries <- c("annual_rain") # result <- epicsawrap::annual_rainfall_summaries(country, station_id, summaries) # +# definitions <- definitions(country = "zm", station_id = "16", +# summaries = summaries) +# epicsadata::get_daily_data(country = country, station_id = station_id) +# # country <- "zm" # station_id_2 <- "16" # summaries_2 <- c("start_rains", "end_rains", "annual_rain", "seasonal_rain") @@ -22,10 +26,10 @@ # test_that("Error is thrown if undefined values", { # # Test case 1: Error is thrown if undefined values # expect_error(epicsawrap::annual_rainfall_summaries(country, station_id, "end_season")) -# +# # # Test case 2: Error is thrown if start_ is not calculated but needed # expect_error(epicsawrap::annual_rainfall_summaries(country, station_id_2, c("end_rains", "seasonal_rain"))) -# +# # # Test case 3: Warning if both end are given and seasonal wanted # expect_warning(epicsawrap::annual_rainfall_summaries(country, station_id_2, c("start_rains", "end_rains", "end_season", "seasonal_rain"))) # }) diff --git a/tests/testthat/test-crop_success_probabilities.R b/tests/testthat/test-crop_success_probabilities.R index ee41901..d8bfe7d 100644 --- a/tests/testthat/test-crop_success_probabilities.R +++ b/tests/testthat/test-crop_success_probabilities.R @@ -5,9 +5,9 @@ # result <- epicsawrap::crop_success_probabilities( # country = "zm", # station_id = "16", -# planting_dates = c(1, 2, 3), -# water_requirements = c(100, 200, 300), -# planting_length = 10, +# planting_dates = c(92, 122, 153), +# water_requirements = c(300, 500, 700), +# planting_length = c(120, 180), # start_before_season = TRUE # ) # @@ -32,3 +32,9 @@ # expect_no_error(result_2) # expect_no_error(result_3) # }) +# +# # Define test cases +# test_that("crop_success_probabilities returns same results whether parameters are defined or not", { +# expect_identical(result[[2]], result_3[[2]]) +# }) +# diff --git a/tests/testthat/test-total_temperature_summaries.R b/tests/testthat/test-total_temperature_summaries.R index 1f5ccd3..7a8fcc1 100644 --- a/tests/testthat/test-total_temperature_summaries.R +++ b/tests/testthat/test-total_temperature_summaries.R @@ -1,7 +1,7 @@ # library(testthat) # # # Test case 1: Test with to = "annual" -# result <- total_temperature_summaries( +# result <- epicsawrap:::total_temperature_summaries( # country = "zm", # station_id = "23", # summaries = c("mean_tmin", "mean_tmax"), @@ -9,7 +9,7 @@ # ) # # # Test case 2: Test with to = "monthly" -# result_2 <- total_temperature_summaries( +# result_2 <- epicsawrap:::total_temperature_summaries( # country = "zm", # station_id = "1", # summaries = c("mean_tmin", "mean_tmax"), @@ -21,7 +21,7 @@ # # Mock the necessary external functions or datasets if needed # expect_length(result, 2) # expect_length(result_2, 2) -# +# # expect_no_error(result) # expect_no_error(result_2) # }) \ No newline at end of file From b62dadf709125003a0f39c3bcc4d7b7e30af6540 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Tue, 10 Oct 2023 12:28:36 +0100 Subject: [PATCH 2/2] adding s_start_doy parameter --- R/annual_rainfall_summaries.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/annual_rainfall_summaries.R b/R/annual_rainfall_summaries.R index c037d83..1c79b00 100644 --- a/R/annual_rainfall_summaries.R +++ b/R/annual_rainfall_summaries.R @@ -91,6 +91,7 @@ annual_rainfall_summaries <- function(country, station_id, summaries = c("annual threshold = definitions$start_rains$threshold, start_day = definitions$start_rains$start_day, end_day = definitions$start_rains$end_day, + s_start_doy = definitions$start_rains$s_start_doy, output = "doy", total_rainfall = as.logical(definitions$start_rains$total_rainfall), over_days = definitions$start_rains$over_days, @@ -119,6 +120,7 @@ annual_rainfall_summaries <- function(country, station_id, summaries = c("annual end_rains <- rpicsa::end_rains(daily, date_time = data_names$date, station = data_names$station, year = data_names$year, rain = data_names$rain, start_day = definitions$end_rains$start_day, end_day = definitions$end_rains$end_day, + s_start_doy = definitions$end_rains$s_start_doy, output = "doy", interval_length = definitions$end_rains$interval_length, min_rainfall = definitions$end_rains$min_rainfall) @@ -144,6 +146,7 @@ annual_rainfall_summaries <- function(country, station_id, summaries = c("annual rain = data_names$rain, start_day = definitions$end_season$start_day, end_day = definitions$end_season$end_day, + s_start_doy = definitions$end_season$s_start_doy, output = "doy", capacity = definitions$end_season$capacity, water_balance_max = definitions$end_season$water_balance_max, @@ -210,7 +213,6 @@ annual_rainfall_summaries <- function(country, station_id, summaries = c("annual stop("start_rains and at least one of end_season or end_rains is required to calculate seasonal_length") } } - list_return <- NULL list_return[[1]] <- c(definitions) list_return[[2]] <- summary_data