Commit e3c07f30 authored by Conor Anderson's avatar Conor Anderson

Increase test coverage.

parent 3dfce8b1
Pipeline #46463682 passed with stages
in 26 minutes and 55 seconds
......@@ -5,22 +5,37 @@ context("Test `find_station()`")
## test finding a station by name with regex
test_that("find_station() can locate a station by name regex", {
df <- find_station("Yell*", glob = TRUE, assume_yes = TRUE)
df <- find_station(c("Yell*", "Tor*"), glob = TRUE, assume_yes = TRUE)
expect_that(df, is_a("hcd_station_list"))
expect_that(df, is_a("tbl_df"))
expect_output(str(df), "8 obs")
expect_output(str(df), "103 obs")
expect_output(str(df), "7 variables")
})
## test finding a station by period
test_that("find_station() can locate a station by period", {
df <- find_station(period = 1840:2015, recodes = TRUE, assume_yes = TRUE)
expect_warning(df <- find_station(period = 2015:1840, assume_yes = TRUE),
"Period not chronological. Using min value to max value.", fixed = TRUE)
expect_that(df, is_a("hcd_station_list"))
expect_that(df, is_a("tbl_df"))
expect_output(str(df), "1 obs")
expect_output(str(df), "7 variables")
})
## test finding a station by period and check for recodes
test_that("find_station() can locate a station by period", {
expect_output(
df <- find_station(period = 1981:2010, type = "hourly", recodes = TRUE,
target = "5051", dist = 0:20, assume_yes = TRUE),
"In addition to the stations found, the following combinations may provide sufficient period data.")
expect_that(df, is_a("hcd_station_list"))
expect_that(df, is_a("tbl_df"))
expect_output(str(df), "1 obs")
expect_output(str(df), "8 variables")
})
## test finding a station by province
test_that("find_station() can locate a station by province", {
df <- find_station(province = "ON", assume_yes = TRUE)
......@@ -48,6 +63,12 @@ test_that("find_station() can locate a station by distance for coordinates", {
expect_output(str(df), "8 variables")
})
## find_station should warn if types are passed incorrectly
test_that("find_station() fails if provice is incorrect", {
expect_warning(find_station(type = c("daily", "monthly", "hourly", "fortnightly"), assume_yes = TRUE),
"One of more types invalid. Omitting.", fixed = TRUE)
})
## find_station should fail if we spell the province incorrectly
test_that("find_station() fails if provice is incorrect", {
expect_error(find_station(province = "Qwebek", assume_yes = TRUE), "One or more province name(s) incorrect.", fixed = TRUE)
......
......@@ -17,3 +17,16 @@ test_that("map_stations() can map a station search result", {
expect_that(map, is_a("leaflet"))
expect_that(map, is_a("htmlwidget"))
})
## test a map of one searched stations
test_that("map_stations() can map sentinel", {
map <- map_stations(df, type = "sentinel")
expect_that(map, is_a("leaflet"))
expect_that(map, is_a("htmlwidget"))
expect_identical(map$x$calls[[1]]$args[[4]]$attribution, "Sentinel-2 cloudless - https://s2maps.eu by EOX IT Services GmbH (Contains modified Copernicus Sentinel data 2016 & 2017)")
})
## map_stations should complain if we don't choose sentinel or osm
test_that("find_station() fails if provice code is incorrect", {
expect_warning(map_stations(df, type = "oms"), "Unrecognized map type. Defaulting to osm.", fixed = TRUE)
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment