tests/testthat/test-extract-all-dp.R

test_that("Read DemProj and AIM data from Spectrum 6.36", {
  pjnz = "../uga-asm-2023-v000.pjnz"

  dp = read.raw.dp(pjnz)

  expect_length(dp.status.projection.valid(dp), 1)
  expect_length(dp.inputs.first.year(dp), 1)
  expect_length(dp.inputs.final.year(dp), 1)
  expect_length(dp.inputs.life.table(dp, direction="wide"), 1)
  expect_length(dp.inputs.use.external.pop(dp, direction="wide"), 2)
  expect_length(dp.inputs.kos.source(dp, direction="wide"), 1)
  expect_length(dp.inputs.csavr.model(dp, direction="wide"), 1)
  expect_length(dp.inputs.csavr.deaths.source(dp) > 0, 1)
  expect_length(dp.inputs.incidence.model(dp, direction="wide"), 1)
  expect_length(dp.inputs.epp.epidemic.first.year(dp, direction="wide"), 1)
  expect_length(dp.inputs.epp.epidemic.type(dp, direction="wide"), 1)
  expect_length(dp.inputs.adult.hiv.mortality.art.scale(dp, direction="wide"), 1)
  expect_length(dp.inputs.art.transmission.reduction(dp, direction="wide"), 1)
  expect_length(dp.inputs.adult.art.adjustment.flag(dp, direction="wide"), 1)
  expect_length(dp.inputs.child.art.adjustment.flag(dp, direction="wide"), 1)
  expect_length(dp.inputs.adult.art.allocation(dp, direction="wide"), 2)
  expect_length(dp.inputs.epp.adjustment.cap(dp, direction="wide"), 1)
  expect_length(dp.inputs.epp.adjustment.enabled(dp, direction="wide"), 1)
  expect_length(dp.inputs.irr.custom(dp, direction="wide"), 1)
  expect_length(dp.inputs.irr.sex.from.epp(dp, direction="wide"), 1)
  expect_length(dp.inputs.irr.pattern(dp, direction="wide"), 1)
  expect_length(dp.inputs.hiv.frr.location(dp, direction="wide"), 1)
  expect_length(dp.inputs.covid19.enabled(dp, direction="wide"), 1)
  expect_length(dp.inputs.adult.hiv.mortality.region(dp, direction="wide"), 1)
  expect_length(dp.inputs.adult.hiv.mortality.art.region(dp, direction="wide"), 1)
  expect_length(dp.inputs.adult.hiv.mortality.custom(dp, direction="wide"), 1)
  expect_length(dp.inputs.adult.hiv.mortality.art.custom(dp, direction="wide"), 1)

  expect_equal(nrow(dp.inputs.tfr(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.pasfr(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.migr.rate(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.migr.dist(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.srb(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.surv(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.e0(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.e0.default(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.external.pop(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.pop.country(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.pop.percent(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.anc.testing(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.hiv.testing(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.kos.data(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.initial.cd4(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.data.options(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.irr.options(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.diagnoses(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.diagnoses.sex(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.diagnoses.sex.age(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.diagnoses.cd4(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.deaths(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.deaths.sex(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.deaths.sex.age(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.deaths.source.names(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.csavr.migr.diagnoses(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.migr.plhiv(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.cd4.progression(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.hiv.mortality.off.art(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.hiv.mortality.art(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.hiv.mortality.art.trend(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.art(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.art.adjustment.value(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.child.art.adjustment.value(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.pmtct(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.pmtct.retention.perinatal(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.pmtct.retention.postnatal(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.art.ltfu(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.child.art.ltfu(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.child.art(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.art.initiations(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.art.reinitiations(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.child.art.initiations(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.child.art.reinitiations(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.child.art.uptake(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.art.by.age(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.incidence(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.nosocomial.infections(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.irr.sex(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.irr.age(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.hiv.frr.age(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.hiv.frr.cd4(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.hiv.frr.art(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.art.monthly(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.adult.ltfu.monthly(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.viral.suppression(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.viral.suppression.threshold(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.survey.hiv.prevalence(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.survey.art.coverage(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.deaths.art.allcause(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.covid19.deaths(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.covid19.pattern(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.inputs.hiv.abortion(dp, direction="wide")) > 0, TRUE)

  expect_equal(nrow(dp.output.births(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.bigpop(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.imr(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.hivpop(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.artpop(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.art.need(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.pmtct(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.pmtct.need(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.incident.hiv(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.deaths.hiv(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.deaths.art(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.deaths.nonhiv(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.art.50plus(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.cd4.15_up(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.cd4.15_49(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.child.hiv.14(dp, direction="wide")) > 0, TRUE)

  expect_equal(nrow(dp.output.csavr.deaths.hiv(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.csavr.incident.hiv(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.csavr.plhiv(dp, direction="wide")) > 0, TRUE)
  expect_equal(nrow(dp.output.csavr.diagnoses(dp, direction="wide")) > 0, TRUE)
})

test_that("Read AIM uncertainty analysis data from Spectrum 6.36", {
  pjnz = "../uga-asm-2023-v000.pjnz"
  expect_length(dp.output.ua.data(pjnz), 4)
})
rlglaubius/SpectrumUtils documentation built on Dec. 20, 2024, 7:31 a.m.