diff --git a/R/get_gsw.R b/R/get_gsw.R index ce673c2a..3350bafa 100644 --- a/R/get_gsw.R +++ b/R/get_gsw.R @@ -1,5 +1,14 @@ .get_gsw <- function(x, statistic = "occurrence", vers_gsw = "v1_4_2021", rundir = tempdir(), verbose = TRUE) { + available_gsw_statistics <- c( + "change", + "occurrence", + "recurrence", + "seasonality", + "transitions" + ) + stopifnot(statistic %in% available_gsw_statistics) + # make the gsw grid and construct urls for intersecting tiles baseurl <- sprintf( "https://storage.googleapis.com/global-surface-water/downloads2021/%s/%s", diff --git a/tests/testthat/test-calc_gsw_change.R b/tests/testthat/test-calc_gsw_change.R index e4aee6a6..3e5275c7 100644 --- a/tests/testthat/test-calc_gsw_change.R +++ b/tests/testthat/test-calc_gsw_change.R @@ -21,6 +21,7 @@ test_that("gsw change works", { expect_equal( chg$global_surface_water_change_mean, - 100 + 100, + tolerance = 1e-4 ) }) diff --git a/tests/testthat/test-calc_gsw_occurrence.R b/tests/testthat/test-calc_gsw_occurrence.R index 5e3e31a3..792d318e 100644 --- a/tests/testthat/test-calc_gsw_occurrence.R +++ b/tests/testthat/test-calc_gsw_occurrence.R @@ -21,6 +21,7 @@ test_that("gsw occurrence works", { expect_equal( occ$global_surface_water_occurrence_mean, - 19.41088415664687 + 19.41088415664687, + tolerance = 1e-4 ) }) diff --git a/tests/testthat/test-calc_gsw_recurrence.R b/tests/testthat/test-calc_gsw_recurrence.R index e1b247ed..5e415195 100644 --- a/tests/testthat/test-calc_gsw_recurrence.R +++ b/tests/testthat/test-calc_gsw_recurrence.R @@ -21,7 +21,8 @@ test_that("gsw recurrence works", { expect_equal( rec$global_surface_water_recurrence_mean, - 22.49229803467092 + 22.49229803467092, + tolerance = 1e-4 ) }) diff --git a/tests/testthat/test-calc_gsw_seasonality.R b/tests/testthat/test-calc_gsw_seasonality.R index 3b32f1d6..c3b6ef45 100644 --- a/tests/testthat/test-calc_gsw_seasonality.R +++ b/tests/testthat/test-calc_gsw_seasonality.R @@ -21,6 +21,7 @@ test_that("gsw seasonality works", { expect_equal( season$global_surface_water_seasonality_mean, - 2.289487662369018 + 2.289487662369018, + tolerance = 1e-4 ) }) diff --git a/tests/testthat/test-calc_gsw_transitions.R b/tests/testthat/test-calc_gsw_transitions.R index a88d9d6d..5a3e140d 100644 --- a/tests/testthat/test-calc_gsw_transitions.R +++ b/tests/testthat/test-calc_gsw_transitions.R @@ -31,7 +31,8 @@ test_that("gsw transitions works", { ) expect_equal( - transitions, - transitions_expected + transitions$area, + transitions_expected$area, + tolerance = 1e-4 ) }) diff --git a/tests/testthat/test-get_gsw.R b/tests/testthat/test-get_gsw.R index 5619655a..a95e77a9 100644 --- a/tests/testthat/test-get_gsw.R +++ b/tests/testthat/test-get_gsw.R @@ -23,17 +23,6 @@ test_that(".get_gsw works", { # Add testing attribute in order to skip downloads attributes(portfolio)$testing <- TRUE - gsw_statistics <- c( - "change", - "occurrence", - "recurrence", - "seasonality", - "transitions" - ) - for (gsw_statistic in gsw_statistics) { - resource_name <- paste0("global_surface_water_", gsw_statistic) - } - expect_error( .get_gsw(portfolio, statistic = "not-available") )