tests/testthat/test-hybrid-choice-group3.R

test_that("hybrid-choice Group 3 files are self-contained", {
  example_directory <- rbiogeme_example_path( "hybrid_choice_models")
  scripts <- c(
    "plot_h07_mode_lv_ordprobit_simult_generated.R",
    "plot_h08_mode_lv_parameter_overrides.R"
  )
  expect_equal(
    sort(list.files(example_directory, pattern = "^plot_h0[78].*\\.R$")),
    sort(scripts)
  )
  for (script in scripts) {
    expect_silent(parse(file.path(example_directory, script)))
  }
})

test_that("h07 reproduces the generated ordered-probit model without Python source output", {
  path <- rbiogeme_example_path( "hybrid_choice_models",
    "plot_h07_mode_lv_ordprobit_simult_generated.R"
  )
  source_text <- paste(readLines(path, warn = FALSE), collapse = "\n")
  expect_match(source_text, "ordered_probit_log_probability")
  expect_match(source_text, "plot_h07_mode_lv_ordprobit_simult_generated")
  expect_false(grepl("writeLines|open\\(.*w", source_text))
})

test_that("h08 declares a fixed generated-parameter override and does not estimate", {
  path <- rbiogeme_example_path( "hybrid_choice_models",
    "plot_h08_mode_lv_parameter_overrides.R"
  )
  source_text <- paste(readLines(path, warn = FALSE), collapse = "\n")
  expect_match(source_text, "parameter_overrides")
  expect_match(source_text, "fixed = TRUE")
  expect_false(grepl("estimate\\(", source_text, fixed = FALSE))
})

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.