tests/testthat/test-crosswalk-validation.R

test_that("Contradictory value mappings are rejected", {
  cw <- tibble::tibble(
    id = c("survey_1", "survey_1"),
    var_name_orig = c("q1", "q1"),
    var_name_target = c("trust", "trust"),
    val_numeric_orig = c(1, 1),
    val_label_orig = c("Yes", "Yes"),
    val_numeric_target = c(0, 1),
    val_label_target = c("Distrust", "Trust")
  )

  expect_error(
    is.crosswalk_table(cw),
    regexp = "Contradictory value mappings"
  )
})

test_that("Many-to-one value mappings are permitted", {
  cw <- tibble::tibble(
    id = c("survey_1", "survey_1"),
    var_name_orig = c("q1", "q1"),
    var_name_target = c("trust", "trust"),
    val_numeric_orig = c(1, 2),
    val_label_orig = c("Strongly agree", "Agree"),
    val_numeric_target = c(1, 1),
    val_label_target = c("Trust", "Trust")
  )

  expect_true(is.crosswalk_table(cw))
})

test_that("Identical repeated value mappings are permitted", {
  cw <- tibble::tibble(
    id = c("survey_1", "survey_1"),
    var_name_orig = c("q1", "q1"),
    var_name_target = c("trust", "trust"),
    val_numeric_orig = c(1, 1),
    val_label_orig = c("Yes", "Yes"),
    val_numeric_target = c(1, 1),
    val_label_target = c("Trust", "Trust")
  )

  expect_true(is.crosswalk_table(cw))
})

Try the retroharmonize package in your browser

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

retroharmonize documentation built on Nov. 29, 2026, 5:06 p.m.