From ce016f69944497d9d6a6fb38fac819714a41ecab Mon Sep 17 00:00:00 2001 From: Danny Colombara Date: Fri, 9 May 2025 15:16:21 -0700 Subject: [PATCH] Critical fix to update to latest CHI standards - chi_race_7 is no longer in rads.data::misc_chi_byvars - replaced it with race4 in the test helper file and test-chi_calc() - confirmed now passes all tests --- tests/testthat/helper.R | 4 ++-- tests/testthat/test-chi_calc.R | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index ad2880e..a937570 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -243,7 +243,7 @@ setup_test_data <- function() { DTIteration <- data.table( id = 1:observations, chi_geo_kc = sample(c('King County',NA_character_), observations, replace = T), - chi_race_7 = factor(sample(c("Asian", "AIAN", "Black", "Hispanic", "NHPI", "White", "Other", "Multiple", NA), observations, replace = T, prob = c(.19,.01,.07,.11,.01,.35,.07,.14,.02)), levels = c("Asian", "AIAN", "Black", "Hispanic", "NHPI", "White", "Other", "Multiple", NA)), + race4 = factor(sample(c("Asian", "AIAN", "Black", "Hispanic", "NHPI", "White", "Multiple", NA), observations, replace = T, prob = c(.19,.01,.07,.11,.01,.42,.14,.02)), levels = c("Asian", "AIAN", "Black", "Hispanic", "NHPI", "White", "Other", "Multiple", NA)), chi_sex = as.factor(sample(c("Male","Female"), observations, replace = T)), chi_geo_region = factor(sample(c("South", "North", "Seattle", "East"), observations, replace = T), levels = c("South","North","Seattle","East")), indicator1 = as.factor(sample(c("never","sometimes", "always", NA), observations, replace = T)), @@ -382,7 +382,7 @@ setup_test_data <- function() { test_analysis_set_twosets <- data.table( #this should work with the generic data set cat1 = rep(c('Regions', 'Gender', 'Race/ethnicity'),2), - cat1_varname = rep(c('chi_geo_region', 'chi_sex', 'chi_race_7'),2), + cat1_varname = rep(c('chi_geo_region', 'chi_sex', 'race4'),2), `_kingcounty` = c('x'), `_wastate` = NA_character_, demgroups = c(rep(NA_character_,3),rep("x", 3)), diff --git a/tests/testthat/test-chi_calc.R b/tests/testthat/test-chi_calc.R index f705071..7cf36f4 100644 --- a/tests/testthat/test-chi_calc.R +++ b/tests/testthat/test-chi_calc.R @@ -7,7 +7,7 @@ test_that("chi_calc performs basic calculations correctly", { DTgeneric <- test_data$my.generic_data #make a denominator come out as 0 DTgeneric$indicator - DTgeneric[chi_race_7 == "White" , indicator1 := "never"] + DTgeneric[race4 == "White" , indicator1 := "never"] result <- chi_calc( ph.data = DTgeneric, ph.instructions = instruction, @@ -18,7 +18,6 @@ test_that("chi_calc performs basic calculations correctly", { small_num_suppress = F ) - expect_s3_class(result, "data.table") expect_true(all(c("result", "lower_bound", "upper_bound") %in% names(result))) expect_true(all(result$result >= 0 & result$result <= 1)) # For proportions