tests/testthat/test_get_weather_four_days.R

context("Testing get_weather_four_days function")

good_appid <- "ea4a67edc7fc8631bf71089ab4ec1c09"
good_city <- "Toronto"

bad_appid <- ""
bad_city <- ""

test_that("Check data integrity",{
  result<-get_weather_four_days(good_appid, good_city)
  
  # Expected outputs
  expect_equal(is.data.frame(result), TRUE) # output is a data frame
  expect_equal(nrow(result), 4) # output is four rows, one for each day of forecast
  expect_equal(ncol(result), 5) # output is five columns
})

test_that('Error in parameters', {
  # expected error:
  expect_error(get_weather_four_days(bad_appid,good_city), "Invalid API key")
  expect_error(get_weather_four_days(good_appid,bad_city), "Invalid city name")
})
UBC-MDS/weatheR documentation built on May 21, 2019, 12:03 p.m.