tests/testthat/test-coverage-interval-status.R

test_that("finite failed intervals remain requested but unavailable", {
  failed <- data.frame(
    conf_low = -1.98,
    conf_high = 1.98,
    interval_available = FALSE,
    method_requested = "profile",
    method_returned = "profile",
    conf_status = "optimization_failed"
  )
  valid <- data.frame(
    conf_low = -1.98,
    conf_high = 1.98,
    interval_available = TRUE,
    method_requested = "profile",
    method_returned = "profile",
    conf_status = "ok"
  )
  incorrectly_available <- transform(failed, interval_available = TRUE)
  wrong_method_status <- transform(valid, conf_status = "bootstrap")

  expect_true(freqTLS:::coverage_interval_status_valid(failed))
  expect_true(freqTLS:::coverage_interval_status_valid(valid))
  expect_false(freqTLS:::coverage_interval_status_available(
    failed$conf_low, failed$conf_high, failed$conf_status
  ))
  expect_true(freqTLS:::coverage_interval_status_available(
    valid$conf_low, valid$conf_high, valid$conf_status
  ))
  expect_false(freqTLS:::coverage_interval_status_valid(incorrectly_available))
  expect_false(freqTLS:::coverage_interval_status_valid(wrong_method_status))
})

test_that("fit and interval status rows cannot contradict fit outcomes", {
  valid <- data.frame(
    n_groups = 3L, replicate = 1L, target = "CTmax",
    fit_converged = TRUE, pd_hess = TRUE, estimate = 36,
    conf_low = 35, conf_high = 37, interval_available = TRUE,
    method_returned = "profile", conf_status = "ok"
  )
  expect_true(freqTLS:::coverage_fit_interval_consistency_valid(valid))

  no_hessian <- transform(valid, pd_hess = FALSE)
  expect_true(freqTLS:::coverage_fit_interval_consistency_valid(no_hessian))
  expect_false(freqTLS:::coverage_fit_interval_consistency_valid(
    transform(no_hessian, method_returned = "wald")
  ))

  failed_fit_with_interval <- transform(valid, fit_converged = FALSE)
  expect_false(freqTLS:::coverage_fit_interval_consistency_valid(
    failed_fit_with_interval
  ))

  unavailable_failure <- transform(
    valid, fit_converged = FALSE, pd_hess = FALSE, estimate = NA_real_,
    conf_low = NA_real_, conf_high = NA_real_, interval_available = FALSE,
    method_returned = NA_character_, conf_status = NA_character_
  )
  expect_true(freqTLS:::coverage_fit_interval_consistency_valid(
    unavailable_failure
  ))
})

test_that("the runner and verifier share one eight-field runtime identity", {
  fields <- freqTLS:::coverage_runtime_identity_fields(
    paste(rep("a", 40L), collapse = ""),
    paste(rep("b", 64L), collapse = ""), "/candidate",
    paste(rep("c", 64L), collapse = ""), "1.9.0", "4.6.0",
    "aarch64-apple-darwin23", "Mersenne-Twister/Inversion/Rejection"
  )
  expect_length(fields, 8L)
  expect_identical(fields[[6L]], "4.6.0")
  expect_identical(fields[[7L]], "aarch64-apple-darwin23")
  expect_identical(fields[[8L]], "Mersenne-Twister/Inversion/Rejection")
  expect_error(freqTLS:::coverage_runtime_identity_fields(
    "", paste(rep("b", 64L), collapse = ""), "/candidate",
    paste(rep("c", 64L), collapse = ""), "1.9.0", "4.6.0",
    "aarch64-apple-darwin23", "Mersenne-Twister/Inversion/Rejection"
  ), "eight non-empty character fields")
})

test_that("available bootstrap intervals require 20 usable refits", {
  bootstrap <- data.frame(
    n_groups = 3L, replicate = 1L, method_requested = "bootstrap",
    fit_converged = TRUE, n_boot_requested = 199L,
    n_boot_converged = 20L, n_boot_failed = 179L,
    bootstrap_error = NA_character_, conf_low = 35, conf_high = 37,
    conf_status = "bootstrap"
  )
  expect_true(freqTLS:::coverage_bootstrap_counts_valid(bootstrap, 199L))
  bootstrap$n_boot_converged <- 19L
  bootstrap$n_boot_failed <- 180L
  expect_false(freqTLS:::coverage_bootstrap_counts_valid(bootstrap, 199L))
})

Try the freqTLS package in your browser

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

freqTLS documentation built on Dec. 4, 2026, 5:11 p.m.