You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
opensensmapR/tests/testthat/test_phenomena.R

41 lines
1000 B
R

context("phenomena")
check_api <- function() {
skip_on_cran()
code <- NA
try(code <- httr::status_code(httr::GET(osem_endpoint())))
if (is.na(code)) skip("API not available")
}
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", {
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")
})