tests/testthat/test-csv.R

context("quantile")

library(data.table)
library(jsonlite)


test_that("data_frame_from_forecast_data() is correct", {
  # test the underlying function that `quantile_data_frame_from_forecast_data()` filters from
  cdc_csv_file <- "data/docs-predictions-exp.csv"
  exp_data_frame <- utils::read.csv(cdc_csv_file, stringsAsFactors = FALSE, colClasses='character')  # "NA" -> NA
  exp_data_frame["" == exp_data_frame] <- NA  # "" -> NA
  exp_data_frame <- data.table(exp_data_frame)
  forecast_data <- jsonlite::read_json("data/docs-predictions.json")
  forecast_data <- convert_forecast_data_dates(forecast_data)  # matches what `download_forecast()` does
  act_data_frame <- data_frame_from_forecast_data(forecast_data)
  expect_equal(act_data_frame, exp_data_frame)
})


test_that("data_frame_from_forecast_data() handles retractions", {
  cdc_csv_file <- "data/docs-predictions-with-retractions-exp.csv"
  exp_data_frame <- utils::read.csv(cdc_csv_file, stringsAsFactors = FALSE, colClasses='character')  # "NA" -> NA
  exp_data_frame["" == exp_data_frame] <- NA  # "" -> NA
  exp_data_frame <- data.table(exp_data_frame)
  forecast_data <- jsonlite::read_json("data/docs-predictions-with-retractions.json")
  forecast_data <- convert_forecast_data_dates(forecast_data)  # matches what `download_forecast()` does
  act_data_frame <- data_frame_from_forecast_data(forecast_data)
  expect_equal(act_data_frame, exp_data_frame)
})

Try the zoltr package in your browser

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

zoltr documentation built on April 4, 2025, 1:27 a.m.