mirror of
https://github.com/sensebox/opensensmapr
synced 2025-02-22 14:53:57 +01:00
add tests for phenomena and box
This commit is contained in:
parent
1712976770
commit
542f2205eb
2 changed files with 68 additions and 0 deletions
30
tests/testthat/test_box.R
Normal file
30
tests/testthat/test_box.R
Normal file
|
@ -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)))
|
||||||
|
})
|
38
tests/testthat/test_phenomena.R
Normal file
38
tests/testthat/test_phenomena.R
Normal file
|
@ -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…
Add table
Reference in a new issue