tests/testthat/test-get_model_metadata.R

context("get_model_metadata")
library(covidHubUtils)
library(dplyr)

test_that("get_model_metadata works: local directory, data-processed folder, all models", {
  actual <- covidHubUtils::get_model_metadata(
    source = "local_hub_repo",
    hub_repo_path = "test-data/test-get_model_designations"
  )

  expected <- data.frame(
    team_name = c("COVIDhub", "COVIDhub", rep("test team name", 5)),
    model_name = c("baseline", "ensemble", "A", "teamB", "C", "D", "E"),
    model = c(
      "COVIDhub-baseline", "COVIDhub-ensemble", "teamA-modelA",
      "teamB-modelB", "teamC-modelC", "teamD-modelD", "teamE-modelE"
    ),
    designation = c(
      "proposed", "primary", "primary", "secondary", "proposed",
      "other", "other"
    ),
    website_url = c(
      NA, "https://covid19forecasthub.org/", NA, NA, NA, NA, NA
    ),
    ensemble_of_hub_models = c(
      NA, TRUE, NA, NA, NA, NA, NA
    ),
    stringsAsFactors = FALSE
  )

  expect_equal(actual, expected)
})

test_that("get_model_metadata works: local directory, data-forecasts folder, all models", {
  actual <- covidHubUtils::get_model_metadata(
    source = "local_hub_repo",
    hub_repo_path = "test-data/test-get_model_designations",
    hub = c("FluSight")
  )
  
  expected <- data.frame(
    team_name = c("TeamA", "TeamB"),
    model_name = c("ModelA", "ModelB"),
    model = c("TeamA-ModelA","TeamB-ModelB"),
    website_url = c(
      "https://covid19forecasthub.org/", "https://covid19forecasthub.org/"
    ),
    designation = c("primary", "primary"),
    ensemble_of_hub_models = c(FALSE, FALSE),
    stringsAsFactors = FALSE
  )
  
  expect_equal(actual, expected)
})

test_that("get_model_metadata works: local directory, data-processed folder, specified models", {
  actual <- covidHubUtils::get_model_metadata(
    source = "local_hub_repo",
    models = c("COVIDhub-baseline", "COVIDhub-ensemble", "teamA-modelA"),
    hub_repo_path = "test-data/test-get_model_designations"
  )

  expected <- data.frame(
    team_name = c("COVIDhub", "COVIDhub", "test team name"),
    model_name = c("baseline", "ensemble", "A"),
    model = c("COVIDhub-baseline", "COVIDhub-ensemble", "teamA-modelA"),
    designation = c("proposed", "primary", "primary"),
    website_url = c(NA, "https://covid19forecasthub.org/", NA),
    ensemble_of_hub_models = c(NA, TRUE, NA),
    stringsAsFactors = FALSE
  )

  expect_equal(actual, expected)
})

test_that("get_model_metadata works: local directory, data-forecasts folder, specified models", {
  actual <- covidHubUtils::get_model_metadata(
    source = "local_hub_repo",
    models = c("TeamA-ModelA"),
    hub_repo_path = "test-data/test-get_model_designations",
    hub = c("FluSight")
  )
  
  expected <- data.frame(
    team_name = c("TeamA"),
    model_name = c("ModelA"),
    model = c("TeamA-ModelA"),
    website_url = c("https://covid19forecasthub.org/"),
    designation = c("primary"),
    ensemble_of_hub_models = c(FALSE),
    stringsAsFactors = FALSE
  )
  
  expect_equal(actual, expected)
})

test_that("get_model_metadata works: local hub repo, space in hub repo path", {
  actual <- covidHubUtils::get_model_metadata(
    source = "local_hub_repo",
    hub_repo_path = "test-data/test-get_model_designations folder",
    models = c("teamA-modelA", "teamB-modelB")
  )

  expected <- data.frame(
    team_name = c(rep("test team name", 2)),
    model_name = c("A", "teamB"),
    model = c("teamA-modelA", "teamB-modelB"),
    designation = c("primary", "secondary"),
    stringsAsFactors = FALSE
  )

  expect_true(dplyr::all_equal(actual, expected))
})
reichlab/covidHubUtils documentation built on Feb. 6, 2024, 1:42 p.m.