tests/testthat/test_oESALC.R

library(checkmate)
library(testthat)
library(magrittr)
context("oESALC")


test_that("oESALC loads the correct file", {
  setPaths(root = system.file("test_datasets", package="rasterTools"))
  
  output <- oESALC(mask = rtGeoms$mask, years = 2005)
  
  expect_class(output, "RasterStack")
})

test_that(("oESALC works with Spatial* mask (that has another crs than the dataset)"), {
  # setPaths(root = system.file("test_datasets", package="rasterTools"))
  # myMask <- gToSp(geom = rtGeoms$mask) %>%
  #   setCRS(crs = projs$longlat)
  # 
  # output <- oESALC(mask = myMask, years = 2005)
  # expect_class(output, "RasterStack")
})

test_that("obtain works with an sf object as mask", {
  # setPaths(root = system.file("test_datasets", package="rasterTools"))
  # myDatasets <- list(list(operator = "oCLC", years = 2000))
  # myMask <- gt_as_sf(geom = rtGeoms$mask)
  # myMask <- setCRS(x = myMask, crs = projs$longlat)
  # 
  # output <- obtain(data = myDatasets, mask = myMask)
  # expect_list(output, len = 1)
  # expect_names(names(output[[1]]), must.include = c("clc"))
})

test_that("obtain works with a geom object as mask", {
  setPaths(root = system.file("test_datasets", package="rasterTools"))
  myDatasets <- list(list(operator = "oCLC", years = 2000))
  
  output <- obtain(data = myDatasets, mask = rtGeoms$mask)
  expect_list(output, len = 1)
  expect_names(names(output[[1]]), must.include = c("clc"))
})

test_that("Error if arguments have wrong value", {
  setPaths(root = system.file("test_datasets", package="rasterTools"))
  
  expect_error(oESALC(mask = "myMask"))
  expect_error(oESALC(mask = rtGeoms$mask, years = "bla"))
  expect_error(oESALC(mask = rtGeoms$mask, years = 1991))
})

test_that("bibliography item has been created", {
  setPaths(root = system.file("test_datasets", package="rasterTools"))
  options(bibliography = NULL)
  
  output <- oESALC(mask = rtGeoms$mask, years = 2005)
  theBib <- getOption("bibliography")
  expect_class(theBib, classes =  "bibentry")
  expect_list(theBib, len = 1)
})
EhrmannS/rasterTools documentation built on Sept. 4, 2019, 10:34 a.m.