tests/testthat/test-mdcev-group1.R

test_that("MDCEV Group 1 scripts are self-contained", {
  example_directory <- rbiogeme_example_path("mdcev_no_outside_good")
  estimation <- paste(
    readLines(file.path(example_directory, "plot_gamma_estimation.R"), warn = FALSE),
    collapse = "\n"
  )
  forecasting <- paste(
    readLines(file.path(example_directory, "plot_gamma_forecasting.R"), warn = FALSE),
    collapse = "\n"
  )

  for (script in c(estimation, forecasting)) {
    expect_match(script, "biogeme_mdcev_model")
    expect_match(script, "model_type = \"gamma_profile\"")
    expect_match(script, "baseline_utilities")
    expect_match(script, "gamma_parameters")
    expect_match(script, "consumed_quantities")
    expect_match(script, "number_of_chosen_alternatives")
    expect_match(script, "prepare_mdcev_example")
  }
  expect_match(estimation, "mdcev_short_summary")
  expect_match(estimation, "mdcev_parameter_table")
  expect_match(forecasting, "mdcev_validate_forecast")
  expect_match(forecasting, "mdcev_forecast_describe")
})

test_that("MDCEV Group 2 scripts are self-contained", {
  example_directory <- rbiogeme_example_path("mdcev_no_outside_good")
  scripts <- vapply(
    c("plot_generalized_estimation.R", "plot_generalized_forecasting.R"),
    function(filename) {
      paste(readLines(file.path(example_directory, filename), warn = FALSE), collapse = "\n")
    },
    character(1)
  )

  for (script in scripts) {
    expect_match(script, "biogeme_mdcev_model")
    expect_match(script, "model_type = \"generalized\"")
    expect_match(script, "baseline_utilities")
    expect_match(script, "gamma_parameters")
    expect_match(script, "alpha_parameters")
    expect_match(script, "consumed_quantities")
    expect_match(script, "prepare_mdcev_example")
  }
  expect_match(scripts[[1L]], "mdcev_short_summary")
  expect_match(scripts[[1L]], "mdcev_parameter_table")
  expect_match(scripts[[2L]], "mdcev_validate_forecast")
  expect_match(scripts[[2L]], "mdcev_forecast_describe")
})

test_that("MDCEV Group 3 scripts are self-contained", {
  example_directory <- rbiogeme_example_path("mdcev_no_outside_good")
  scripts <- vapply(
    c("plot_translated_estimation.R", "plot_translated_forecasting.R"),
    function(filename) {
      paste(readLines(file.path(example_directory, filename), warn = FALSE), collapse = "\n")
    },
    character(1)
  )

  for (script in scripts) {
    expect_match(script, "biogeme_mdcev_model")
    expect_match(script, "model_type = \"translated\"")
    expect_match(script, "baseline_utilities")
    expect_match(script, "gamma_parameters")
    expect_match(script, "alpha_parameters")
    expect_match(script, "scale_parameter")
    expect_match(script, "consumed_quantities")
    expect_match(script, "prepare_mdcev_example")
  }
  expect_match(scripts[[1L]], "mdcev_short_summary")
  expect_match(scripts[[1L]], "mdcev_parameter_table")
  expect_match(scripts[[2L]], "mdcev_validate_forecast")
  expect_match(scripts[[2L]], "mdcev_forecast_describe")
})

test_that("MDCEV Group 4 scripts are self-contained", {
  example_directory <- rbiogeme_example_path("mdcev_no_outside_good")
  scripts <- vapply(
    c("plot_non_monotonic_estimation.R", "plot_non_monotonic_forecasting.R"),
    function(filename) {
      paste(readLines(file.path(example_directory, filename), warn = FALSE), collapse = "\n")
    },
    character(1)
  )

  for (script in scripts) {
    expect_match(script, "biogeme_mdcev_model")
    expect_match(script, "model_type = \"non_monotonic\"")
    expect_match(script, "baseline_utilities")
    expect_match(script, "gamma_parameters")
    expect_match(script, "alpha_parameters")
    expect_match(script, "mu_utilities")
    expect_match(script, "scale_parameter")
    expect_match(script, "consumed_quantities")
    expect_match(script, "prepare_mdcev_example")
  }
  expect_match(scripts[[1L]], "mdcev_short_summary")
  expect_match(scripts[[1L]], "mdcev_parameter_table")
  expect_match(scripts[[2L]], "11L, 12L")
  expect_match(scripts[[2L]], "mdcev_validate_forecast")
  expect_match(scripts[[2L]], "mdcev_forecast_describe")
})

Try the rbiogeme package in your browser

Any scripts or data that you put into this service are public.

rbiogeme documentation built on Sept. 29, 2026, 5:09 p.m.