tests/testthat/test-crosswalk_basketball.R

test_that(".bb_normalize_name strips accents, suffixes, and punctuation", {
  skip_on_cran()
  expect_equal(.bb_normalize_name("Breanna Stewart"), "breanna stewart")
  expect_equal(.bb_normalize_name("A'ja Wilson"), "aja wilson")
  expect_equal(.bb_normalize_name("Nikola Jokić"), "nikola jokic")
  expect_equal(.bb_normalize_name("Karl-Anthony Towns"), "karl anthony towns")
  expect_equal(.bb_normalize_name("Gary Payton II"), "gary payton")
  expect_equal(.bb_normalize_name("  Sabrina   Ionescu  "), "sabrina ionescu")
  expect_equal(.bb_normalize_name(NA_character_), "")
})

test_that(".bb_normalize_team normalizes city+name strings", {
  skip_on_cran()
  expect_equal(.bb_normalize_team("Las Vegas Aces"), "las vegas aces")
  expect_equal(.bb_normalize_team("Los Angeles Sparks"), "los angeles sparks")
  expect_equal(.bb_normalize_team("The Storm"), "storm")
  expect_equal(.bb_normalize_team("Connecticut  Sun"), "connecticut sun")
})

test_that(".bb_to_eastern returns the correct local ET game date", {
  skip_on_cran()
  expect_equal(.bb_to_eastern("2024-06-02T01:30:00Z"), as.Date("2024-06-01"))
  expect_equal(.bb_to_eastern("2024-06-02T16:00:00Z"), as.Date("2024-06-02"))
  expect_equal(.bb_to_eastern(as.Date("2024-07-04")), as.Date("2024-07-04"))
  expect_true(is.na(.bb_to_eastern(NA_character_)))
})

test_that(".bb_normalize_college_team gives a consistent contracting key", {
  skip_on_cran()
  expect_equal(.bb_normalize_college_team("Missouri State"), .bb_normalize_college_team("Missouri St."))
  expect_equal(.bb_normalize_college_team("Texas A&M"), "texas a and m")
  expect_equal(
    .bb_normalize_college_team("Saint Mary's"),
    .bb_normalize_college_team("St. Mary's")
  )
  expect_equal(.bb_normalize_college_team("Ohio State"), "ohio st")
  expect_equal(.bb_normalize_college_team("Kansas St."), "kansas st")
  expect_equal(.bb_normalize_college_team(NA_character_), "")
})

test_that(".bb_fuzzy_match returns typed empty frame when left has zero rows", {
  skip_on_cran()
  left <- data.frame(
    .block = character(), .id = character(), .name_key = character(),
    stringsAsFactors = FALSE
  )
  right <- data.frame(
    .block = character(), .id = character(), .name_key = character(),
    stringsAsFactors = FALSE
  )
  m <- .bb_fuzzy_match(left, right)
  expect_s3_class(m, "data.frame")
  expect_equal(nrow(m), 0)
  expect_true(all(c(".block", "left_id", "right_id",
                    "match_method", "match_confidence") %in% names(m)))
})

test_that(".bb_fuzzy_match does not match empty name keys", {
  skip_on_cran()
  left <- data.frame(
    .block = c("A", "A"),
    .id    = c("L1", "L2"),
    .name_key = c("", ""),
    stringsAsFactors = FALSE
  )
  right <- data.frame(
    .block = c("A", "A"),
    .id    = c("R1", "R2"),
    .name_key = c("", ""),
    stringsAsFactors = FALSE
  )
  m <- .bb_fuzzy_match(left, right, min_confidence = 0.92)
  expect_equal(nrow(m), 2)
  expect_true(all(is.na(m$right_id)))
  expect_true(all(m$match_method == "unmatched"))
})

test_that(".bb_fuzzy_match does exact, fuzzy, tiebreak, and unmatched", {
  skip_on_cran()
  left <- data.frame(
    .block = c("A", "A", "A", "B"),
    .id = c("L1", "L2", "L3", "L4"),
    .name_key = c("breanna stewart", "sabrina ionescu",
                  "aja wilson", "diana taurasi"),
    .jersey = c("30", "20", "22", "3"),
    stringsAsFactors = FALSE
  )
  right <- data.frame(
    .block = c("A", "A", "A"),
    .id = c("R1", "R2", "R3"),
    .name_key = c("breanna stewart", "sabrina ionescu", "aja wlson"),
    .jersey = c("30", "20", "22"),
    stringsAsFactors = FALSE
  )
  m <- .bb_fuzzy_match(left, right, min_confidence = 0.92)
  expect_equal(m$right_id[m$left_id == "L1"], "R1")
  expect_equal(m$match_method[m$left_id == "L1"], "exact_name")
  expect_equal(m$right_id[m$left_id == "L3"], "R3")
  expect_equal(m$match_method[m$left_id == "L3"], "fuzzy_jw")
  expect_gt(m$match_confidence[m$left_id == "L3"], 0.92)
  expect_true(is.na(m$right_id[m$left_id == "L4"]))
  expect_equal(m$match_method[m$left_id == "L4"], "unmatched")
})

Try the wehoop package in your browser

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

wehoop documentation built on Aug. 25, 2026, 1:06 a.m.