tests/testthat/test-get_scenario_budget.R

# work around to ensure the package can read in the data
# needs to be saved in the inst folder
path <- system.file("testdata", "three1", "scenario_0", package = "mm.reoptimise") # not ran
path2 <- system.file("testdata", "three2", "scenario_0", package = "mm.reoptimise") # not ran
path3 <- system.file("testdata", "three1", "scenario_1", package = "mm.reoptimise") # already ran

path <- c(path, path2, path3)
scenario_multiple <- purrr::map(path, create_scenario)

# NOTE: update this to test all scenarios in the folder via map / map2
scenario <- scenario_multiple[[1]]

period <- get_scenario_period(scenario, type = "all")
kpi1 <- get_scenario_kpi1(scenario, period[1])
kpi2 <- get_scenario_kpi2(scenario, period[1], kpi1[2])
kpi3 <- get_scenario_kpi3(scenario, period[1], kpi1[2], kpi2[1])

budget <- get_scenario_budget(scenario)
output <- purrr::map_dbl(scenario_multiple, get_scenario_budget)

test_that("function returns correctly", {

      expect_equal(output, c(6e7, 6e7, 6e7))
      expect_equal(typeof(output), "double")

})
cath-parkinson/mm.reoptimise documentation built on May 12, 2022, 3:34 p.m.