forked from SymbolixAU/googleway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SymbolixAU
committed
Jun 5, 2016
1 parent
697e4e8
commit 907f1b7
Showing
3 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,126 @@ | ||
context("Google distance") | ||
|
||
## api keys are not included in the package | ||
## and so can't be tested | ||
skip_api_key <- function() { | ||
skip("key not available") | ||
} | ||
|
||
test_that("google_distance returns data.frame", { | ||
## skip this test | ||
skip_api_key() | ||
|
||
df <- google_distance(origins = c(-37.8179746, 144.9668636), | ||
destinations = c(-37.81659, 144.9841), | ||
mode = "walking", | ||
key = key, | ||
output_format = "data.frame") | ||
|
||
expect_equal(class(df), "list") | ||
expect_equal(names(df), c("geocoded_waypoints","routes","status")) | ||
expect_equal(length(df[[1]]), 3) | ||
}) | ||
|
||
|
||
|
||
test_that("origins are lat/lon", { | ||
|
||
expect_error(google_distance(origins = list(c(144.9668636)), | ||
destinations = c(-37.81659, 144.9841), | ||
mode = "driving", | ||
key = "abc"), | ||
"Origins elements must be either a numeric vector of lat/lon coordinates, or an address string") | ||
|
||
}) | ||
|
||
test_that("Destinations are lat/lon", { | ||
|
||
expect_error(google_distance(origins = list(c(-37.8179746, 144.9668636)), | ||
destinations = c(-37.81659), | ||
mode = "driving", | ||
key = "abc"), | ||
"Destinations elements must be either a numeric vector of lat/lon coordinates, or an address string") | ||
|
||
}) | ||
|
||
test_that("Avoid is a valid type", { | ||
|
||
expect_error(google_distance(origins = list(c(-37.8179746, 144.9668636)), | ||
destinations = list(c(-37.81659, 144.9841)), | ||
avoid = "dont avoid", | ||
key = "abc", | ||
output_format = "data.frame"), | ||
"avoid must be one of tolls, highways, ferries or indoor") | ||
}) | ||
|
||
test_that("Departure time is not in the past",{ | ||
|
||
expect_error(google_distance(origins = list(c(-37.8179746, 144.9668636)), | ||
destinations = list(c(-37.81659, 144.9841)), | ||
departure_time = as.POSIXct("2015-01-01"), | ||
key = "abc", | ||
output_format = "data.frame"), | ||
"departure_time must not be in the past") | ||
|
||
}) | ||
|
||
test_that("waypoints only valid for certain modes",{ | ||
|
||
expect_error(google_distance(origins = "Melbourne Airport", | ||
destinations = "Sorrento", | ||
waypoints = list(c(-37.81659, 144.9841), | ||
"Ringwood, Victoria"), | ||
mode = "transit", | ||
key = "abc"), | ||
"waypoints are only valid for driving, walking or bicycling modes") | ||
}) | ||
|
||
test_that("waypoints are a list",{ | ||
|
||
expect_error(google_distance(origins = "Melbourne Airport", | ||
destinations = "Sorrento", | ||
waypoints = c(-37.81659, 144.9841), | ||
key = "abc"), | ||
"waypoints must be a list") | ||
}) | ||
|
||
test_that("map url is a single string",{ | ||
|
||
expect_error(google_distance(origins = "Melbourne Airport", | ||
destinations = "Sorrento", | ||
alternatives = c(FALSE, TRUE), | ||
key = "abc"), | ||
"invalid map_url") | ||
}) | ||
|
||
|
||
test_that("transit_mode issues warning when mode != transit",{ | ||
|
||
expect_warning(google_distance(origins = "Melbourne Airport, Australia", | ||
destinations = "Portsea, Melbourne, Australia", | ||
departure_time = Sys.time() + (24 * 60 * 60), | ||
waypoints = list(via = c(-37.81659, 144.9841), | ||
via = "Ringwood, Victoria"), | ||
transit_mode = "bus", | ||
key = "abc"), | ||
"You have specified a transit_mode, but are not using mode = 'transit'. Therefore this argument will be ignored") | ||
|
||
}) | ||
|
||
|
||
test_that("warning when both arrival and departure times supplied", { | ||
|
||
expect_warning(google_distance(origins = "Melbourne Airport, Australia", | ||
destinations = "Portsea, Melbourne, Australia", | ||
departure_time = Sys.time() + (24 * 60 * 60), | ||
arrival_time = Sys.time() + (24 * 60 * 60), | ||
key = "abc"), | ||
"you have supplied both an arrival_time and a departure_time - only one is allowed. The arrival_time will be ignored") | ||
|
||
}) | ||
|
||
|
||
|
||
|
||
|
||
|