tests/testthat/test-edge_cases.R

# Edge case tests for cdisc_compare safety features

test_that("WHERE clause validation catches bad inputs", {
  df <- data.frame(STUDYID = "S1", DOMAIN = "DM", USUBJID = "U1", SEX = "M",
                   stringsAsFactors = FALSE)
  expect_error(
    cdisc_compare(df, df, domain = "DM", standard = "SDTM", where = ""),
    "non-empty"
  )
  expect_error(
    cdisc_compare(df, df, domain = "DM", standard = "SDTM", where = 42),
    "non-empty character"
  )
  expect_error(
    cdisc_compare(df, df, domain = "DM", standard = "SDTM", where = "SEX ==== 'M'"),
    "Invalid WHERE|WHERE filter failed"
  )
})

test_that("'+' id_vars bare plus errors", {
  df <- data.frame(STUDYID = "S1", DOMAIN = "DM", USUBJID = "U1",
                   stringsAsFactors = FALSE)
  expect_error(
    cdisc_compare(df, df, id_vars = c("+")),
    "at least one additional"
  )
})

test_that("cdisc_compare tolerance validation", {
  df <- data.frame(STUDYID = "S1", DOMAIN = "DM", USUBJID = "U1",
                   stringsAsFactors = FALSE)
  expect_error(
    cdisc_compare(df, df, domain = "DM", standard = "SDTM", tolerance = -5),
    "non-negative finite"
  )
})

Try the clinCompare package in your browser

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

clinCompare documentation built on Feb. 19, 2026, 1:07 a.m.