tests/testthat/test-lookup_table.R

# function(icd_codes, ref_df, data_col, one_to_one=TRUE)




test_that("returns same values in same order", {
  ref <- dplyr::tibble(idx = LETTERS[1:4],
                       out = c("Alfa", "Bravo",
                               "Charlie", "Delta"))

  test_lookup_idx <- function(codes){
    expect_equal(object = lookup_table(codes, ref, "idx")[["idx"]],
                 expected = codes)
  }
  test_lookup_out <- function(codes, expected_out){
    expect_equal(object = lookup_table(codes, ref, "idx")[["out"]],
                 expected = expected_out)
  }

  # Cases where at least one value supplied can be found
  test_lookup_idx("A")               # Simple case
  test_lookup_idx(c("A", "B"))       # Multiple
  test_lookup_idx(c("A", NA, "B"))   # NA values
  test_lookup_idx("E")


  # Test odd cases where only supplied NA values
  lookup_table(NA, ref, "idx") %>%
    expect_equal(NA) %>%
    expect_warning()

  # Test case where no value found
  test_lookup_idx("E")
  test_lookup_out("E", NA_character_)


  test_lookup_idx(c("E", NA))
  test_lookup_out(c("E", NA), c(NA_character_, NA))
  lookup_table(c("E", NA), ref, "idx")






  expect_equal(2 * 2, 4)
})
HunterRatliff1/hcup documentation built on Aug. 6, 2023, 6:10 p.m.