Skip to content

Commit

Permalink
update tests for removed T5 data
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffeaton committed Jan 2, 2025
1 parent 50cee08 commit 4e19b40
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/setup-model-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a_naomi_mf <- naomi_model_frame(a_area_merged,
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
artattend = FALSE,
spectrum_population_calibration = "none",
psnu_level = NULL)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/setup-run-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ a_hintr_options <- list(
calendar_quarter_t2 = "CY2023Q4",
calendar_quarter_t3 = "CY2024Q3",
calendar_quarter_t4 = "CY2025Q3",
calendar_quarter_t5 = "CY2026Q3",
## calendar_quarter_t5 = "CY2026Q3",
survey_prevalence = "DEMO2020PHIA",
survey_art_coverage = "DEMO2020PHIA",
survey_recently_infected = "DEMO2020PHIA",
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-01-run-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ test_that("model run can be calibrated", {
## * 9 areas
## * 3 output times - 16 indicators
## * 1 output time - 5 indicators [NOT INCLUDED IN PLOT OUTPUTS]
## * 1 output time - 4 indicators [NOT INCLUDED IN PLOT OUTPUTS]
## * **T5 dropped** -> 0 output time - 4 indicators [NOT INCLUDED IN PLOT OUTPUTS]
##
## ANC indicators outputs
## 4 = number or output times
## 9 = number of ANC indicators
## 9 = number of areas
## 12 = number of ANC age groups
expect_equal(nrow(calibrated_output_obj$output_package$indicators),
33 * 3 * 9 * (3 * 16 + 1 * 5 + 1 * 4) + 4 * 9 * 9 * 12)
33 * 3 * 9 * (3 * 16 + 1 * 5 + 0 * 4) + 4 * 9 * 9 * 12)

## Plot data output: T3 and T4 indicators not included -> fewer rows
plot_data_output <- read_hintr_output(calibrated_output$plot_data_path)
Expand Down Expand Up @@ -505,7 +505,7 @@ test_that("Model can be run without .shiny90 file", {
## Check there is some data
## 11 indicators (5 fewer because missing awareness of status indicators)
expect_equal(nrow(indicators_output$output_package$indicators),
33 * 3 * 9 * (3 * 11 + 1 * 5 + 1 * 4) + 4 * 9 * 9 * 12)
33 * 3 * 9 * (3 * 11 + 1 * 5 + 0 * 4) + 4 * 9 * 9 * 12)
})

test_that("hintr_run_model can skip validation", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-02-model-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ test_that("Handle backwards regression when T4 and T5 options are missing", {

# Check that T4 and T5 are 24- and 36-months after T3 when options are not specificed
options_old$calendar_quarter_t4 <- NULL
options_old$calendar_quarter_t5 <- NULL
## options_old$calendar_quarter_t5 <- NULL
naomi_data <- naomi_prepare_data(a_hintr_data, options_old)

t3 <- calendar_quarter_to_quarter_id(naomi_data$model_options$calendar_quarter_t3)
t4 <- calendar_quarter_to_quarter_id(naomi_data$model_options$calendar_quarter_t4)
t5 <- calendar_quarter_to_quarter_id(naomi_data$model_options$calendar_quarter_t5)
## t5 <- calendar_quarter_to_quarter_id(naomi_data$model_options$calendar_quarter_t5)

expect_equal(t4 - t3, 6)
expect_equal(t5 - t3, 9)
## expect_equal(t5 - t3, 9)

})
42 changes: 23 additions & 19 deletions tests/testthat/test-04-model-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test_that("population calibration options", {
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "none")

expect_equal(mf_none$spectrum_calibration$population_raw,
Expand All @@ -77,15 +77,15 @@ test_that("population calibration options", {
expect_equal(sum(mf_none$mf_model$population_t1 +
mf_none$mf_model$population_t2 +
mf_none$mf_model$population_t3 +
mf_none$mf_model$population_t4 +
mf_none$mf_model$population_t5
mf_none$mf_model$population_t4 ## +
## mf_none$mf_model$population_t5
),
sum(mf_none$spectrum_calibration$population_calibrated))
expect_equal(sum(mf_none$mf_model$population_t1 +
mf_none$mf_model$population_t2 +
mf_none$mf_model$population_t3 +
mf_none$mf_model$population_t4 +
mf_none$mf_model$population_t5
mf_none$mf_model$population_t4 ## +
## mf_none$mf_model$population_t5
),
sum(mf_none$spectrum_calibration$population_raw))

Expand All @@ -102,7 +102,7 @@ test_that("population calibration options", {
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "national")

expect_false(sum(mf_nat$spectrum_calibration$population_raw) ==
Expand All @@ -112,14 +112,16 @@ test_that("population calibration options", {
expect_equal(sum(mf_nat$mf_model$population_t1 +
mf_nat$mf_model$population_t2 +
mf_nat$mf_model$population_t3 +
mf_nat$mf_model$population_t4 +
mf_nat$mf_model$population_t5),
mf_nat$mf_model$population_t4 ## +
## mf_nat$mf_model$population_t5
),
sum(mf_nat$spectrum_calibration$population_calibrated))
expect_equal(sum(mf_nat$mf_model$population_t1 +
mf_nat$mf_model$population_t2 +
mf_nat$mf_model$population_t3 +
mf_nat$mf_model$population_t4 +
mf_nat$mf_model$population_t5),
mf_nat$mf_model$population_t4 ## +
## mf_nat$mf_model$population_t5
),
sum(mf_nat$spectrum_calibration$population_spectrum))


Expand All @@ -132,7 +134,7 @@ test_that("population calibration options", {
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "subnational")

expect_false(sum(mf_subnat$spectrum_calibration$population_raw) ==
Expand All @@ -142,14 +144,16 @@ test_that("population calibration options", {
expect_equal(sum(mf_subnat$mf_model$population_t1 +
mf_subnat$mf_model$population_t2 +
mf_subnat$mf_model$population_t3 +
mf_subnat$mf_model$population_t4 +
mf_subnat$mf_model$population_t5),
mf_subnat$mf_model$population_t4 ## +
## mf_subnat$mf_model$population_t5
),
sum(mf_subnat$spectrum_calibration$population_calibrated))
expect_equal(sum(mf_subnat$mf_model$population_t1 +
mf_subnat$mf_model$population_t2 +
mf_subnat$mf_model$population_t3 +
mf_subnat$mf_model$population_t4 +
mf_subnat$mf_model$population_t5),
mf_subnat$mf_model$population_t4 ## +
## mf_subnat$mf_model$population_t5
),
sum(mf_subnat$spectrum_calibration$population_spectrum))

expect_error(
Expand All @@ -162,7 +166,7 @@ test_that("population calibration options", {
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "jibberish"),
"spectrum_calibration_option \"jibberish\" not found."
)
Expand Down Expand Up @@ -293,7 +297,7 @@ test_that("naomi_model_frame() interpolated population depends on quarter specif
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "subnational")


Expand All @@ -319,7 +323,7 @@ test_that("naomi_model_frame() interpolated population depends on quarter specif
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "subnational")


Expand Down Expand Up @@ -348,7 +352,7 @@ test_that("naomi_model_frame() interpolated population depends on quarter specif
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
spectrum_population_calibration = "subnational")

## Outputs should match for T2 (CY2018Q4 -- mid-year)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-05-Lproj.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test_that("Lproj returns", {
calendar_quarter2 = "CY2019Q2",
calendar_quarter3 = "CY2022Q4",
calendar_quarter4 = "CY2023Q4",
calendar_quarter5 = "CY2024Q4",
## calendar_quarter5 = "CY2024Q4",
spectrum_population_calibration = "subnational")

mfA <- naomi_mfA$mf_model
Expand Down Expand Up @@ -71,7 +71,7 @@ test_that("Lproj returns", {
calendar_quarter2 = "CY2023Q2",
calendar_quarter3 = "CY2023Q4",
calendar_quarter4 = "CY2024Q2",
calendar_quarter5 = "CY2024Q4",
## calendar_quarter5 = "CY2024Q4",
spectrum_population_calibration = "subnational")

mfB <- naomi_mfB$mf_model
Expand Down Expand Up @@ -105,7 +105,7 @@ test_that("Lproj returns", {
calendar_quarter2 = "CY2019Q2",
calendar_quarter3 = "CY2023Q4",
calendar_quarter4 = "CY2024Q2",
calendar_quarter5 = "CY2024Q4",
## calendar_quarter5 = "CY2024Q4",
spectrum_population_calibration = "subnational")

mfC <- naomi_mfC$mf_model
Expand Down Expand Up @@ -145,7 +145,7 @@ test_that("Lproj returns", {
calendar_quarter2 = "CY2019Q4",
calendar_quarter3 = "CY2023Q4",
calendar_quarter4 = "CY2024Q2",
calendar_quarter5 = "CY2024Q4",
## calendar_quarter5 = "CY2024Q4",
spectrum_population_calibration = "subnational")

mfD <- naomi_mfD$mf_model
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-objective-function.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_that("R implementation matches C++", {
calendar_quarter2 = "CY2018Q4",
calendar_quarter3 = "CY2019Q2",
calendar_quarter4 = "CY2022Q3",
calendar_quarter5 = "CY2023Q3",
## calendar_quarter5 = "CY2023Q3",
artattend = TRUE,
spectrum_population_calibration = "subnational")

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-outputs.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("traidure hooks work in model outputs", {
out_en <- output_package(a_fit_sample, a_naomi_data)
expect_setequal(out_en$meta_period$quarter_label,
c("March 2016", "December 2018", "June 2019", "September 2022", "September 2023"))
c("March 2016", "December 2018", "June 2019", "September 2022"))
expect_setequal(out_en$meta_indicator$indicator_label[out_en$meta_indicator$indicator %in% c("art_coverage", "prevalence")],
c("ART coverage", "HIV prevalence"))
expect_setequal(out_en$meta_indicator$description[out_en$meta_indicator$indicator %in% c("art_coverage", "prevalence")],
Expand All @@ -12,7 +12,7 @@ test_that("traidure hooks work in model outputs", {

out_fr <- output_package(a_fit_sample, a_naomi_data)
expect_setequal(out_fr$meta_period$quarter_label,
c("Mars 2016", "Décembre 2018", "Juin 2019", "Septembre 2022", "Septembre 2023"))
c("Mars 2016", "Décembre 2018", "Juin 2019", "Septembre 2022"))
expect_setequal(out_fr$meta_indicator$indicator_label[out_fr$meta_indicator$indicator %in% c("art_coverage", "prevalence")],
c("Prévalence du VIH", "Couverture TARV"))
expect_setequal(out_fr$meta_indicator$description[out_fr$meta_indicator$indicator %in% c("art_coverage", "prevalence")],
Expand Down Expand Up @@ -576,7 +576,7 @@ test_that("writing output package translates labels", {
## area_level_label comes from input data (not translated)
expect_true("Prévalence du VIH" %in% read$indicators$indicator_label)
expect_setequal(read$indicators$quarter_label,
c("Septembre 2020", "Décembre 2023", "Septembre 2024", "Septembre 2025", "Septembre 2026"))
c("Septembre 2020", "Décembre 2023", "Septembre 2024", "Septembre 2025"))
## age group label currently doesn't have translations
expect_true("all ages" %in% read$indicators$age_group_label)

Expand Down

0 comments on commit 4e19b40

Please sign in to comment.