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

test_that("hybrid-choice Group 1 files and Optima data are self-contained", {
  example_directory <- rbiogeme_example_path( "hybrid_choice_models")
  expect_true(file.exists(file.path(example_directory, "optima.dat")))
  expect_equal(
    sort(list.files(example_directory, pattern = "^plot_h0[1-3].*\\.R$")),
    sort(c(
      "plot_h01_mode_logit.R",
      "plot_h02_lv_mimic_gauss.R",
      "plot_h03_mode_lv_gauss_seq.R"
    ))
  )
  for (file in list.files(example_directory, pattern = "^plot_h0[1-3].*\\.R$", full.names = TRUE)) {
    expect_silent(parse(file))
  }
})

test_that("Optima preparation matches native filtering and derived columns", {
  skip_if_not(
    identical(Sys.getenv("RBIOGEME_RUN_INTEGRATION"), "1"),
    "Set RBIOGEME_RUN_INTEGRATION=1 to run Optima integration tests"
  )
  skip_if_not(
    rbiogeme_test_configure_python(),
    "Set RBIOGEME_PYTHON to a compatible native Biogeme interpreter"
  )

  example_directory <- rbiogeme_example_path( "hybrid_choice_models")
  data <- read.delim(
    file.path(example_directory, "optima.dat"),
    check.names = FALSE,
    stringsAsFactors = FALSE
  )
  source(file.path(example_directory, "optima.R"))
  database <- optima_database(data)

  expect_equal(nrow(database$data), 889L)
  expect_equal(biogeme_database_filtered_row_count(database), 889L)
  expect_equal(length(biogeme_database_row_ids(database)), 889L)
  expect_true(all(c(
    "worker", "car_is_available", "normalized_weight", "number_of_cars",
    "TimePT_hour", "TimeCar_hour", "PurpHWH", "top_manager",
    "car_oriented_parents", "high_education", "low_education",
    "used_to_go_to_school_by_car"
  ) %in% names(database$data)))
})

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.