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

test_that("hybrid-choice Group 2 files are self-contained", {
  example_directory <- rbiogeme_example_path( "hybrid_choice_models")
  scripts <- c(
    "plot_h04_mode_lv_gauss_simult.R",
    "plot_h05_mode_lv_ordlogit_simult.R",
    "plot_h06_mode_lv_ordprobit_simult.R"
  )
  expect_true(file.exists(file.path(example_directory, "optima.dat")))
  expect_equal(
    sort(list.files(example_directory, pattern = "^plot_h0[4-6].*\\.R$")),
    sort(scripts)
  )
  for (script in scripts) {
    path <- file.path(example_directory, script)
    expect_silent(parse(path))
    source_text <- paste(readLines(path, warn = FALSE), collapse = "\n")
    expect_match(source_text, "biogeme_model\\(")
    expect_match(source_text, "estimate\\(")
    expect_match(source_text, "prepare_optima_example")
  }
})

test_that("hybrid-choice Group 2 keeps the two native ordinal distributions distinct", {
  example_directory <- rbiogeme_example_path( "hybrid_choice_models")
  ordered_logit <- paste(
    readLines(file.path(example_directory, "plot_h05_mode_lv_ordlogit_simult.R"), warn = FALSE),
    collapse = "\n"
  )
  ordered_probit <- paste(
    readLines(file.path(example_directory, "plot_h06_mode_lv_ordprobit_simult.R"), warn = FALSE),
    collapse = "\n"
  )
  expect_match(ordered_logit, "ordered_logit_log_probability")
  expect_match(ordered_probit, "ordered_probit_log_probability")
  expect_false(grepl("ordered_probit_log_probability", ordered_logit, fixed = TRUE))
  expect_false(grepl("ordered_logit_log_probability", ordered_probit, fixed = TRUE))
})

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.