Skip to content

Commit

Permalink
Merge pull request #39 from IDEMSInternational/LC_changes
Browse files Browse the repository at this point in the history
Adding unit tests
  • Loading branch information
lilyclements authored Jul 4, 2023
2 parents 471d152 + 84a12e8 commit 7e76570
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Imports:
magrittr,
purrr,
rlang,
rpicsa
rpicsa,
testthat
Remotes:
IDEMSInternational/epicsadata,
IDEMSInternational/rpicsa
31 changes: 31 additions & 0 deletions tests/testthat/test-annual_rainfall_summaries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# library(testthat)
# library(rpicsa)
#
# # Test case 1
# country <- "zm"
# station_id <- "01122"
# summaries <- c("annual_rain")
# result <- epicsawrap::annual_rainfall_summaries(country, station_id, summaries)
#
# country <- "zm"
# station_id_2 <- "16"
# summaries_2 <- c("start_rains", "end_rains", "annual_rain", "seasonal_rain")
# result_2 <- epicsawrap::annual_rainfall_summaries(country, station_id_2, summaries_2)
#
# test_that("Correct summaries are calculated", {
# # Test case 2
# expect_no_error(result)
# # Test case 3 (add more test cases if needed)
# expect_no_error(result_2)
# })
#
# 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")))
# })
34 changes: 34 additions & 0 deletions tests/testthat/test-crop_success_probabilities.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# library(testthat)
#
# # External functions call
# # Test case 1: Test with all parameter
# 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,
# start_before_season = TRUE
# )
#
# # Test case 2: Test with missing planting_length parameter
# result_2 <- epicsawrap::crop_success_probabilities(
# country = "zm",
# station_id = "16",
# planting_dates = c(1, 2, 3),
# water_requirements = c(100, 200, 300),
# start_before_season = TRUE
# )
#
# # Test case 2: Test with all missing parameters
# result_3 <- epicsawrap::crop_success_probabilities(
# country = "zm",
# station_id = "16"
# )
#
# # Define test cases
# test_that("crop_success_probabilities returns correct results", {
# expect_no_error(result)
# expect_no_error(result_2)
# expect_no_error(result_3)
# })
20 changes: 20 additions & 0 deletions tests/testthat/test-season_start_probabilities.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# library(testthat)
#
# # External functions call
# # Test case 1: Test with all parameters
# result <-
# season_start_probabilities(
# country = "zm",
# station_id = "16",
# start_dates = c(10, 20, 100)
# )
#
# # Test case 2: Test with missing parameters
# result_2 <-
# season_start_probabilities(country = "zm", station_id = "16")
#
# # Define test cases
# test_that("season_start_probabilities returns correct results", {
# expect_no_error(result)
# expect_no_error(result_2)
# })
27 changes: 27 additions & 0 deletions tests/testthat/test-total_temperature_summaries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# library(testthat)
#
# # Test case 1: Test with to = "annual"
# result <- total_temperature_summaries(
# country = "zm",
# station_id = "23",
# summaries = c("mean_tmin", "mean_tmax"),
# to = "annual"
# )
#
# # Test case 2: Test with to = "monthly"
# result_2 <- total_temperature_summaries(
# country = "zm",
# station_id = "1",
# summaries = c("mean_tmin", "mean_tmax"),
# to = "monthly"
# )
#
# # Define test cases
# test_that("total_temperature_summaries returns correct results", {
# # 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)
# })

0 comments on commit 7e76570

Please sign in to comment.