tests/testthat/test-assisted-group4.R

assisted_group4_files <- function() {
  rbiogeme_example_path(
    "assisted",
    c("plot_b06everything.R", "plot_b07everything_assisted.R")
  )
}

test_that("assisted group 4 examples are self-contained", {
  files <- assisted_group4_files()
  expect_true(all(file.exists(files)))
  for (file in files) {
    expect_silent(parse(file = file))
    contents <- paste(readLines(file, warn = FALSE), collapse = "\n")
    expect_match(contents, "biogeme_beta")
    expect_match(contents, "segmentation_catalogs")
    expect_match(contents, "generic_alt_specific_catalogs")
    expect_match(contents, "model_catalog")
    expect_match(contents, "prepare_swissmetro_example")
    expect_match(contents, "filter_purpose = FALSE")
  }
  expect_match(
    paste(readLines(files[[1L]], warn = FALSE), collapse = "\n"),
    "count_number_of_specifications"
  )
  expect_match(
    paste(readLines(files[[1L]], warn = FALSE), collapse = "\n"),
    "432 specifications"
  )
  expect_match(
    paste(readLines(files[[2L]], warn = FALSE), collapse = "\n"),
    "assisted_specification"
  )
  expect_match(
    paste(readLines(files[[2L]], warn = FALSE), collapse = "\n"),
    "negative_time_cost"
  )
})

test_that("b06 reports the native exhaustive-search limit", {
  skip_if_not(
    identical(Sys.getenv("RBIOGEME_RUN_INTEGRATION"), "1"),
    "Set RBIOGEME_RUN_INTEGRATION=1 to run assisted integration tests"
  )
  skip_if_not(
    rbiogeme_test_configure_python(),
    "Set RBIOGEME_PYTHON to a compatible native Biogeme interpreter"
  )
  data_path <- rbiogeme_test_swissmetro_path()
  skip_if(!nzchar(data_path), "Set RBIOGEME_SWISSMETRO_DATA to the Swissmetro .dat file")

  output_directory <- tempfile("rbiogeme-assisted-b06-")
  rscript <- file.path(R.home("bin"), "Rscript")
  output <- system2(
    rscript,
    c(
      "--vanilla",
      assisted_group4_files()[[1L]],
      paste0("--data=", data_path),
      paste0("--python=", Sys.getenv("RBIOGEME_PYTHON")),
      paste0("--output=", output_directory)
    ),
    stdout = TRUE,
    stderr = TRUE
  )
  expect_null(attr(output, "status"))
  expect_true(any(grepl("Native catalog count: 432", output, fixed = TRUE)))
  expect_true(any(grepl("too many.*432.*maximum is 100", output, ignore.case = 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.