Skip to content

Commit

Permalink
update tests + parameter checks
Browse files Browse the repository at this point in the history
  • Loading branch information
khufkens committed Oct 31, 2018
1 parent a91a260 commit ce75e3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
7 changes: 7 additions & 0 deletions R/coordinate_conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
#'}

sin_to_ll <- function(x, y){

# check parameters
if(missing(x) | missing(y)){
stop("please provide a coordinate pair in sinusoidal projection...")
}

# convert to sf object
coords <- sf::st_as_sf(x = data.frame(as.numeric(x),
as.numeric(y),
stringsAsFactors = FALSE),
Expand Down
33 changes: 18 additions & 15 deletions tests/testthat/test_main_functions.r
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@ test_that("test mt_batch_subset()",{

# test coordinate conversions




test_that("test mt_batch_subset()",{
test_that("test coordinate transforms",{

subset <- mt_subset(
product = "MOD11A2",
Expand All @@ -262,21 +259,16 @@ test_that("test mt_batch_subset()",{
progress = FALSE
)

# bind with the original dataframe
subset <- cbind(subset, lat_lon)

# test conversion
expect_is(
sin_to_ll(subset$xllcorner, subset$yllcorner)
sin_to_ll(x = subset$xllcorner, y = subset$yllcorner)
,
"data.frame"
)

# test conversion
expect_is(
sin_to_ll(subset$xllcorner, subset$yllcorner)
,
"data.frame"
# test conversion missing parameter
expect_error(
sin_to_ll(x = subset$xllcorner)
)

# test sf bounding box conversion
Expand All @@ -288,9 +280,20 @@ test_that("test mt_batch_subset()",{
lat = x['latitude_ll'],
cell_size = x['cellsize'],
nrows = x['nrows'],
ncols = x['ncols'])[[1]]
}),
ncols = x['ncols'])
})[[1]],
"sfc"
)

# test sf bounding box conversion missing parameter
expect_error(
apply(
cbind(subset, sin_to_ll(subset$xllcorner, subset$yllcorner)),
1, function(x){
ll_to_bb(lat = x['latitude_ll'],
cell_size = x['cellsize'],
nrows = x['nrows'],
ncols = x['ncols'])
})
)
})

0 comments on commit ce75e3f

Please sign in to comment.