1
0
Fork 0
mirror of https://github.com/sensebox/opensensmapr synced 2025-02-22 14:53:57 +01:00
opensensmapR/tests/testthat/test_phenomena.R
Norwin f69cf62b27
fail gracefully when api is not available (#27)
more robust error handling when API not available (#26)
2019-05-16 12:35:52 +02:00

35 lines
869 B
R

source('testhelpers.R')
context('phenomena')
try({
boxes = osem_boxes()
all_phen = unique(unlist(boxes$phenomena))
})
test_that('phenomena from boxes is a list of counts', {
check_api()
phenomena = osem_phenomena(boxes)
expect_true(is.numeric(unlist(phenomena)))
expect_true(is.list(phenomena))
})
test_that('phenomena from boxes has all phenomena', {
check_api()
phenomena = osem_phenomena(boxes)
expect_true(all(all_phen %in% names(phenomena)))
expect_true(all(names(phenomena) %in% all_phen))
})
test_that('phenomena from a not sensebox data.frame returns error', {
check_api()
expect_error(osem_phenomena(list()), 'no applicable method')
expect_error(osem_phenomena(data.frame()), 'no applicable method')
boxes_df = boxes
class(boxes_df) = c('data.frame')
expect_error(osem_phenomena(boxes_df), 'no applicable method')
})