tests/testthat/test-get_scenario_kpi3.R

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

path <- c(path, path2, path3)
scenario_multiple <- purrr::map(path, create_scenario)[c(1,3)] # need to update tests to test 2nd scenario

# period_list <- purrr::map(scenario_multiple,
#                            get_scenario_period) %>% purrr::map(1)
#
# kpi1_list <- purrr::map(scenario_multiple,
#                    get_scenario_kpi1,
#                    period_list) %>% purrr::map(1)
#
# kpi2_list <- purrr::map(scenario_multiple,
#                        get_scenario_kpi2,
#                        period_list,
#                        kpi1_list) %>% purrr::map(1)

kpi3_list <- purrr::map(scenario_multiple,
                        get_scenario_kpi3,
                        "month",
                        "Profit",
                        "Profit")

output <- kpi3_list


test_that("get_scenario_kpi returns a string", {

      expect_equal(output %>% unlist() %>% typeof(),
                   "character")
      expect_true(output %>% unlist() %>% length() >= 1)

      test <- purrr::map(kpi3_list, nchar) %>% purrr::map(1) %>% unlist() >= 1

      expect_equal(test %>% sum() ,
                  output %>% length)

})

# after run optimisatation  -------------------------------------

# scenario_multiple <- lapply(scenario_multiple,
#                             add_optim_elements,
#                             subset_kpi_level1_id = 1,
#                             subset_kpi_level2_id = 1,
#                             subset_kpi_level3_id = 1,
#                             subset_period_level1 = "month")

# this function doesn't run for one of the three scenarios
# scenario_multiple <- lapply(scenario_multiple,
#                             run_optim)

# test_that("get_scenario_period returns a string", {

      # expect_equal(typeof(output), "character")
      # expect_equal(typeof(output2), "character")
      # expect_true(length(output) >= 1)
      # expect_true(nchar(output[1]) > 0)
      # expect_true(nchar(output2) > 0)

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