Skip to content

Commit

Permalink
restructure first linear_pool test
Browse files Browse the repository at this point in the history
Co-authored-by: Evan Ray <elray1@users.noreply.github.com>
  • Loading branch information
lshandross and elray1 committed Aug 4, 2023
1 parent 17eb1ec commit f307132
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions tests/testthat/test-linear_pool.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,40 @@ library(matrixStats)
library(dplyr)
library(tidyr)

# set up simple data for test cases
quantile_outputs <- expand.grid(
stringsAsFactors = FALSE,
model_id = letters[1:4],
location = c("222", "888"),
horizon = 1, #week
target = "inc death",
target_date = as.Date("2021-12-25"),
output_type = "quantile",
output_type_id = c(.1, .5, .9),
value = NA_real_)
test_that("non-default columns are dropped from output", {
# set up simple data for test cases
quantile_outputs <- expand.grid(
stringsAsFactors = FALSE,
model_id = letters[1:4],
location = c("222", "888"),
horizon = 1, #week
target = "inc death",
target_date = as.Date("2021-12-25"),
output_type = "quantile",
output_type_id = c(.1, .5, .9),
value = NA_real_)

v2.1 <- quantile_outputs$value[quantile_outputs$location == "222" &
quantile_outputs$value[quantile_outputs$location == "222" &
quantile_outputs$output_type_id == .1] <-
c(10, 30, 15, 20)
v2.5 <- quantile_outputs$value[quantile_outputs$location == "222" &
c(10, 30, 15, 20)
quantile_outputs$value[quantile_outputs$location == "222" &
quantile_outputs$output_type_id == .5] <-
c(40, 40, 45, 50)
v2.9 <- quantile_outputs$value[quantile_outputs$location == "222" &
c(40, 40, 45, 50)
quantile_outputs$value[quantile_outputs$location == "222" &
quantile_outputs$output_type_id == .9] <-
c(60, 70, 75, 80)
v8.1 <- quantile_outputs$value[quantile_outputs$location == "888" &
c(60, 70, 75, 80)
quantile_outputs$value[quantile_outputs$location == "888" &
quantile_outputs$output_type_id == .1] <-
c(100, 300, 400, 250)
v8.5 <- quantile_outputs$value[quantile_outputs$location == "888" &
c(100, 300, 400, 250)
quantile_outputs$value[quantile_outputs$location == "888" &
quantile_outputs$output_type_id == .5] <-
c(150, 325, 500, 300)
v8.9 <- quantile_outputs$value[quantile_outputs$location == "888" &
c(150, 325, 500, 300)
quantile_outputs$value[quantile_outputs$location == "888" &
quantile_outputs$output_type_id == .9] <-
c(250, 350, 500, 350)

cdf_outputs <- mutate(quantile_outputs,output_type="cdf")
c(250, 350, 500, 350)

fweight2 <- data.frame(model_id = letters[1:4],
location = "222",
weight = 0.1 * (1:4))
fweight8 <- data.frame(model_id = letters[1:4],
location = "888",
weight = 0.1 * (4:1))
fweight <- bind_rows(fweight2, fweight8)
cdf_outputs <- mutate(quantile_outputs, output_type="cdf")


test_that("non-default columns are dropped from output", {
output_names <- quantile_outputs %>%
dplyr::mutate(extra_col_1 = "a", extra_col_2 = "a") %>%
linear_pool(
Expand Down

0 comments on commit f307132

Please sign in to comment.