add tests for phenomena and box

pull/17/head
nuest 7 years ago
parent 1712976770
commit 542f2205eb

@ -0,0 +1,30 @@
context("box")
check_api <- function() {
code <- NA
try(code <- httr::status_code(httr::GET(osem_endpoint())))
if (is.na(code)) skip("API not available")
}
try({
boxes <- osem_boxes()
})
test_that("a box can be converted to sf object", {
check_api()
box <- osem_box(boxes$X_id[[1]])
box_sf <- sf::st_as_sf(box)
expect_true(sf::st_is_simple(box_sf))
expect_true("sf" %in% class(box_sf))
})
test_that("a box converted to sf object keeps all attributes", {
check_api()
box <- osem_box(boxes$X_id[[1]])
box_sf <- sf::st_as_sf(box)
expect_true(all(names(box) %in% names(box_sf)))
})

@ -0,0 +1,38 @@
context("phenomena")
check_api <- function() {
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")
})
Loading…
Cancel
Save