tests/testthat/test-geocode.R

with_mock_api({
  test_that("single known call returns correct co-ordinates", {
    co <- geocode("sydney")
    expect_equal(c(co$latitude, co$longitude), c(-33.86785, 151.20732))
  })

  test_that("multiple calls return correctly", {
    co <- geocode("paris", 2)
    ex <- c("France", "United States")
    expect_equal(co$country, ex)
  })

  test_that("non-string inputs return an error", {
    expect_error(geocode(1, 2))
    expect_error(geocode("sydney", "two"))
  })

  test_that("nonsense inputs return no matches", {
    expect_error(geocode("sdlkfsjsdf"), "No matches found")
  })
})

Try the openmeteo package in your browser

Any scripts or data that you put into this service are public.

openmeteo documentation built on Oct. 25, 2023, 5:07 p.m.