tests/testthat/test-argument-array.R

test_that("check array validation with single item types", {

  arr2 = openeo:::Array$new(name = "array_typed",items = list(type="string"))
  arr2$setValue(c("2016", "2017", "2018", "2019", "2020", "2021"))
  validation = arr2$validate()
  testthat::expect(length(validation)==0,failure_message = paste0("Validation failed with reason: ",validation)) 
  
})

test_that("check array validation with single item types and list parameter", {
  
  arr2 = openeo:::Array$new(name = "array_typed",items = list(type="number"))
  arr2$setValue(list(2016, 2017, 2018, 2019, 2020, 2021))
  validation = arr2$validate()
  testthat::expect(length(validation)==0,failure_message = paste0("Validation failed with reason: ",validation)) 
  
})

test_that("check array validation with single item types and list parameter with error", {
  
  arr2 = openeo:::Array$new(name = "array_typed",items = list(type="number"))
  arr2$setValue(list(2016, 2017, 2018, 2019, "2020", 2021))
  validation = arr2$validate()
  testthat::expect(length(validation) > 0,failure_message = paste0("Error was not spotted")) 
  
})

test_that("check array validation with multiple item types", {

  # the solution is that it is too complex to validate locally and the back-end will check
  arr2 = openeo:::Array$new(name = "array_typed",items = list(type=c("number","string")))
  arr2$setValue(c("2016", "2017", "2018", "2019", "2020", "2021"))
  validation = arr2$validate()
  testthat::expect(length(validation)==0,failure_message = paste0("Validation failed with reason: ",validation)) 
  
})

Try the openeo package in your browser

Any scripts or data that you put into this service are public.

openeo documentation built on Nov. 17, 2022, 5:07 p.m.