Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hereR.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 5727d5b4-fdcf-4de3-8771-c889c90ac857

RestoreWorkspace: Default
SaveWorkspace: Default
Expand Down
14 changes: 8 additions & 6 deletions tests/testthat/test-autosuggest.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ test_that("autosuggest works", {
expect_error(autosuggest(" "), "'address' contains empty strings.")

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$autosuggest_response
},
suggestion <- autosuggest(address = poi$city),
{
suggestion <- autosuggest(address = poi$city)

# Tests
expect_s3_class(suggestion, "data.frame", exact = TRUE),
expect_equal(length(unique(suggestion$id)), length(poi$city))
# Tests
expect_s3_class(suggestion, "data.frame", exact = TRUE)
expect_equal(length(unique(suggestion$id)), length(poi$city))
}
)
})
28 changes: 16 additions & 12 deletions tests/testthat/test-connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ test_that("connection works", {

## Test with API response mock
# Route segments: "summary = FALSE"
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$connection_response
},
connections <- connection(origin = poi[3:4, ], destination = poi[5:6, ], summary = FALSE),
{
connections <- connection(origin = poi[3:4, ], destination = poi[5:6, ], summary = FALSE)

# Tests
expect_equal(any(sf::st_geometry_type(connections) != "LINESTRING"), FALSE),
expect_equal(length(unique(connections$id)), 2)
# Tests
expect_equal(any(sf::st_geometry_type(connections) != "LINESTRING"), FALSE)
expect_equal(length(unique(connections$id)), 2)
}
)

# Route summary: "summary = FALSE"
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$connection_response
},
connections <- connection(origin = poi[3:4, ], destination = poi[5:6, ], summary = TRUE),
{
connections <- connection(origin = poi[3:4, ], destination = poi[5:6, ], summary = TRUE)

# Tests
expect_equal(any(sf::st_geometry_type(connections) != "MULTILINESTRING"), FALSE),
expect_equal(length(unique(connections$id)), 2)
# Tests
expect_equal(any(sf::st_geometry_type(connections) != "MULTILINESTRING"), FALSE)
expect_equal(length(unique(connections$id)), 2)
}
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ test_that("flow works", {
expect_is(flow(aoi = aoi[aoi$code == "LI", ], url_only = TRUE), "character")

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$flow_response
},
flows <- flow(aoi = aoi[aoi$code == "LI", ]),
{
flows <- flow(aoi = aoi[aoi$code == "LI", ])

# Tests
expect_equal(class(flows), c("sf", "data.frame")),
expect_equal(any(sf::st_geometry_type(flows) != "MULTILINESTRING"), FALSE)
# Tests
expect_equal(class(flows), c("sf", "data.frame"))
expect_equal(any(sf::st_geometry_type(flows) != "MULTILINESTRING"), FALSE)
}
)
})
38 changes: 21 additions & 17 deletions tests/testthat/test-geocode.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,33 @@ test_that("geocode works", {


# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$geocode_response
},
geocoded <- geocode(address = poi$city),
{
geocoded <- geocode(address = poi$city)

# Tests
expect_s3_class(geocoded, c("sf", "data.frame"), exact = TRUE),
expect_true(all(sf::st_geometry_type(geocoded) == "POINT")),
expect_equal(nrow(geocoded), length(poi$city))
# Tests
expect_s3_class(geocoded, c("sf", "data.frame"), exact = TRUE)
expect_true(all(sf::st_geometry_type(geocoded) == "POINT"))
expect_equal(nrow(geocoded), length(poi$city))
}
)
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$geocode_response
},
geocoded <- geocode(address = poi$city, alternatives = TRUE, sf = FALSE),
{
geocoded <- geocode(address = poi$city, alternatives = TRUE, sf = FALSE)

# Tests
expect_s3_class(geocoded, "data.frame", exact = TRUE),
expect_gt(nrow(geocoded), length(poi$city)),
expect_type(geocoded[["lat_position"]], "double"),
expect_type(geocoded[["lng_position"]], "double"),
expect_type(geocoded[["lat_access"]], "double"),
expect_type(geocoded[["lng_access"]], "double")
# Tests
expect_s3_class(geocoded, "data.frame", exact = TRUE)
expect_gt(nrow(geocoded), length(poi$city))
expect_type(geocoded[["lat_position"]], "double")
expect_type(geocoded[["lng_position"]], "double")
expect_type(geocoded[["lat_access"]], "double")
expect_type(geocoded[["lng_access"]], "double")
}
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-incident.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ test_that("incidents works", {
), "character")

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$incident_response
},
incidents <- incident(aoi = aoi),
{
incidents <- incident(aoi = aoi)

# Tests
expect_equal(class(incidents), c("sf", "data.frame")),
expect_equal(any(sf::st_geometry_type(incidents) != "MULTILINESTRING"), FALSE)
# Tests
expect_equal(class(incidents), c("sf", "data.frame"))
expect_equal(any(sf::st_geometry_type(incidents) != "MULTILINESTRING"), FALSE)
}
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-intermodal_route.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ test_that("intermodal_route works", {
expect_error(intermodal_route(origin = poi, destination = poi, url_only = "not_a_bool"), "'url_only' must be a 'boolean' value.")

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$intermodal_route_response
},
intermodal_routes <- intermodal_route(origin = poi[1:2, ], destination = poi[3:4, ]),
{
intermodal_routes <- intermodal_route(origin = poi[1:2, ], destination = poi[3:4, ])

# Tests
expect_s3_class(intermodal_routes, c("sf", "data.frame"), exact = TRUE),
expect_true(all(sf::st_geometry_type(intermodal_routes) == "LINESTRING"))
# Tests
expect_s3_class(intermodal_routes, c("sf", "data.frame"), exact = TRUE)
expect_true(all(sf::st_geometry_type(intermodal_routes) == "LINESTRING"))
}
)
})
19 changes: 10 additions & 9 deletions tests/testthat/test-isoline.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ test_that("isoline works", {
expect_error(isoline(poi = poi, url_only = "not_a_bool"), "'url_only' must be a 'boolean' value.")

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$isoline_response
},
{
# With and without aggregation
isolines_aggr <- isoline(poi = poi, aggregate = TRUE)
isolines_mult <- isoline(poi = poi, aggregate = FALSE)

# With and without aggregation
isolines_aggr <- isoline(poi = poi, aggregate = TRUE),
isolines_mult <- isoline(poi = poi, aggregate = FALSE),

# Tests
expect_equal(any(sf::st_geometry_type(isolines_aggr) != "MULTIPOLYGON"), FALSE),
expect_equal(any(sf::st_geometry_type(isolines_mult) != "POLYGON"), FALSE)
# Tests
expect_equal(any(sf::st_geometry_type(isolines_aggr) != "MULTIPOLYGON"), FALSE)
expect_equal(any(sf::st_geometry_type(isolines_mult) != "POLYGON"), FALSE)
}
)
})
34 changes: 19 additions & 15 deletions tests/testthat/test-reverse_geocode.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,33 @@ test_that("reverse_geocode works", {
expect_error(reverse_geocode(poi = poi, results = "-100"), "'results' must be of type 'numeric'.")

# Test with API response mock: sf
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$reverse_geocode_response
},
reverse <- reverse_geocode(poi = poi, results = 3, sf = TRUE),
{
reverse <- reverse_geocode(poi = poi, results = 3, sf = TRUE)

# Tests
expect_s3_class(reverse, c("sf", "data.frame"), exact = TRUE),
expect_true(all(sf::st_geometry_type(reverse) == "POINT"))
# Tests
expect_s3_class(reverse, c("sf", "data.frame"), exact = TRUE)
expect_true(all(sf::st_geometry_type(reverse) == "POINT"))
}
)

# Test with API response mock: data.frame
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$reverse_geocode
},
reverse <- reverse_geocode(poi = poi, results = 3, sf = FALSE),
{
reverse <- reverse_geocode(poi = poi, results = 3, sf = FALSE)

# Tests
expect_s3_class(reverse, "data.frame", exact = TRUE),
expect_type(reverse[["lat_position"]], "double"),
expect_type(reverse[["lng_position"]], "double"),
expect_type(reverse[["lat_access"]], "double"),
expect_type(reverse[["lng_access"]], "double")
# Tests
expect_s3_class(reverse, "data.frame", exact = TRUE)
expect_type(reverse[["lat_position"]], "double")
expect_type(reverse[["lng_position"]], "double")
expect_type(reverse[["lat_access"]], "double")
expect_type(reverse[["lng_access"]], "double")
}
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-route.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ test_that("route works", {
expect_false(all(grepl(",tolls&tolls[summaries]=total&tolls[vignettes]=all", route(origin = poi, destination = poi, transport_mode = "bicycle", vignettes = FALSE, url_only = TRUE), fixed = TRUE)))

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$route_response
},
routes <- route(origin = poi[1:2, ], destination = poi[3:4, ]),
{
routes <- route(origin = poi[1:2, ], destination = poi[3:4, ])

# Tests
expect_equal(any(sf::st_geometry_type(routes) != "LINESTRING"), FALSE),
expect_equal(nrow(routes), nrow(poi[1:2, ]))
# Tests
expect_equal(any(sf::st_geometry_type(routes) != "LINESTRING"), FALSE)
expect_equal(nrow(routes), nrow(poi[1:2, ]))
}
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-route_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ test_that("route_matrix works", {
expect_error(route_matrix(origin = poi, destination = poi, url_only = "not_a_bool"), "'url_only' must be a 'boolean' value.")

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$route_matrix_response
},
r_mat <- route_matrix(origin = poi),
{
r_mat <- route_matrix(origin = poi)

# Tests
expect_is(r_mat, "data.frame"),
expect_equal(nrow(r_mat), nrow(poi)**2)
# Tests
expect_is(r_mat, "data.frame")
expect_equal(nrow(r_mat), nrow(poi)**2)
}
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-station.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ test_that("station works", {
expect_error(weather(poi = poi, url_only = "not_a_bool"), "'url_only' must be a 'boolean' value.")

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$station_response
},
stations <- station(poi = poi),
{
stations <- station(poi = poi)

# Tests
expect_equal(any(sf::st_geometry_type(stations) != "POINT"), FALSE),
expect_equal(length(unique(stations$id)), nrow(poi))
# Tests
expect_equal(any(sf::st_geometry_type(stations) != "POINT"), FALSE)
expect_equal(length(unique(stations$id)), nrow(poi))
}
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-weather_alerts.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ test_that("weather alerts works", {
expect_error(weather(poi = poi, url_only = "not_a_bool"), "'url_only' must be a 'boolean' value.")

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$weather_alerts_response
},
weather_alerts <- weather(poi = poi, product = "alerts"),
{
weather_alerts <- weather(poi = poi, product = "alerts")

# Tests
expect_equal(any(sf::st_geometry_type(weather_alerts) != "POINT"), FALSE),
expect_equal(nrow(weather_alerts), nrow(poi))
# Tests
expect_equal(any(sf::st_geometry_type(weather_alerts) != "POINT"), FALSE)
expect_equal(nrow(weather_alerts), nrow(poi))
}
)
})
14 changes: 8 additions & 6 deletions tests/testthat/test-weather_forecast_astronomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ test_that("weather forecast_astronomy works", {
data(poi)

# Test with API response mock
with_mock(
"hereR:::.async_request" = function(url, rps) {
with_mocked_bindings(
.async_request = function(url, rps) {
hereR:::mock$weather_forecast_astronomy_response
},
weather_forecast_astronomy <- weather(poi = poi, product = "forecast_astronomy"),
{
weather_forecast_astronomy <- weather(poi = poi, product = "forecast_astronomy")

# Tests
expect_equal(any(sf::st_geometry_type(weather_forecast_astronomy) != "POINT"), FALSE),
expect_equal(nrow(weather_forecast_astronomy), nrow(poi))
# Tests
expect_equal(any(sf::st_geometry_type(weather_forecast_astronomy) != "POINT"), FALSE)
expect_equal(nrow(weather_forecast_astronomy), nrow(poi))
}
)
})
Loading
Loading