Skip to content

Commit

Permalink
Merge pull request #34 from getwilds/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
realbp authored Feb 22, 2024
2 parents 52cea05 + 4de9a36 commit 636532b
Show file tree
Hide file tree
Showing 27 changed files with 337 additions and 12 deletions.
4 changes: 2 additions & 2 deletions R/handle-alcohol.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' Handles Women's Alcohol Values to Code
#' Handles Alcohol Values to Code
#'
#' This function returns a matching code value for Alcohol for the api to use to get data from State Cancer Profiles
#'
#' @param alcohol binge drinking (4+ drinks on one occasion for women, 5+ drinks for one occasion for men), ages 21+
#'
#' @importFrom rlang is_na
#'
#' @returns A string for its respective Women's Health Value
#' @returns A string for its respective Alcohol Value
#'
#' @examples
#' \dontrun{
Expand Down
4 changes: 2 additions & 2 deletions R/handle-cancer.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Handles Education Values to Code
#' Handles Cancer Values to Code
#'
#' This function returns a matching code value for a Education for the api to use to get data from State Cancer Profiles
#' This function returns a matching code value for a Cancer for the api to use to get data from State Cancer Profiles
#'
#' @param cancer Either "all cancer sites","bladder", "brain & ons", "breast (female)", "breast (female in situ)", "cervix",
#' "childhood (ages <15, all sites)", "childhood (ages <20, all sites)", "colon & rectum", "esophagus",
Expand Down
2 changes: 1 addition & 1 deletion R/handle-year.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ handle_year <-function(year) {

year_code <- year_mapping[year]

if (is_na(year_mapping)) {
if (is_na(year_code)) {
stop("Invalid year input, please check the documentation for valid inputs")
}

Expand Down
4 changes: 2 additions & 2 deletions man/handle_alcohol.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/handle_cancer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/testthat/test-handle-age.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Test Handle age
#'
#' This testthat file tests the handle-age function
test_that("handle age correctly maps age", {
result <- sapply(c("under 19 years", "under 65 years", "all ages"), handle_age)
expected <- c(`under 19 years` = "175", `under 65 years` = "006", `all ages` = "001")

expect_equal(result, expected)
})

test_that("handle age expects errors for incorrect arguments", {
expect_error(handle_age("carrot"))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-handle-alcohol.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Test Handle alcohol
#'
#' This testthat file tests the handle-age function
test_that("handle_alcohol correctly maps alcohol", {
result <- sapply(c("binge drinking (4+ drinks on one occasion for women, 5+ drinks for one occasion for men), ages 21+"), handle_alcohol)
expected <- c(`binge drinking (4+ drinks on one occasion for women, 5+ drinks for one occasion for men), ages 21+` = "v505")

expect_equal(result, expected)
})

test_that("handle_alcohol expects errors for incorrect arguments", {
expect_error(handle_alcohol("carrot"))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-handle-cancer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Test Handle cancer
#'
#' This testthat file tests the handle-cancer function
test_that("handle cancer correctly maps cancer", {
result <- sapply(c("all cancer sites", "breast (female)", "prostate"), handle_cancer)
expected <- c(`all cancer sites` = "001", `breast (female)` = "055", `prostate` = "066")

expect_equal(result, expected)
})

test_that("handle cancer expects errors for incorrect arguments", {
expect_error(handle_cancer("carrot"))
})
15 changes: 15 additions & 0 deletions tests/testthat/test-handle-diet-exercise.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' Test Handle diet_exercise
#'
#' This testthat file tests the handle-diet_exercise function
test_that("handle diet_exercise correctly maps diet_exercise", {
result <- sapply(c("bmi is healthy, ages 20+", "bmi is obese, ages 20+",
"consumed 1 or more fruits per day"), handle_diet_exercise)
expected <- c(`bmi is healthy, ages 20+` = "v01", `bmi is obese, ages 20+` = "v02",
`consumed 1 or more fruits per day` = "v50")

expect_equal(result, expected)
})

test_that("handle diet_exercise expects errors for incorrect arguments", {
expect_error(handle_diet_exercise("carrot"))
})
15 changes: 15 additions & 0 deletions tests/testthat/test-handle-education.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' Test Handle education
#'
#' This testthat file tests the handle-education function
test_that("handle education correctly maps education", {
result <- sapply(c("less than 9th grade", "at least high school",
"at least bachelors degree"), handle_education)
expected <- c(`less than 9th grade` = "00004", `at least high school` = "00109",
`at least bachelors degree` = "00006")

expect_equal(result, expected)
})

test_that("handle education expects errors for incorrect arguments", {
expect_error(handle_education("carrot"))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-handle-food.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Test Handle food
#'
#' This testthat file tests the handle-food function
test_that("handle food correctly maps food", {
result <- sapply(c("food insecurity", "limited access to healthy food"), handle_food)
expected <- c(`food insecurity` = "03003", `limited access to healthy food` = "03004")

expect_equal(result, expected)
})

test_that("handle food expects errors for incorrect arguments", {
expect_error(handle_food("carrot"))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-handle-income.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Test Handle income
#'
#' This testthat file tests the handle-income function
test_that("handle income correctly maps income", {
result <- sapply(c("median family income", "median household income"), handle_income)
expected <- c(`median family income` = "00010", `median household income` = "00011")

expect_equal(result, expected)
})

test_that("handle income expects errors for incorrect arguments", {
expect_error(handle_income("carrot"))
})
18 changes: 18 additions & 0 deletions tests/testthat/test-handle-insurance.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' Test Handle insurance
#'
#' This testthat file tests the handle-insurance function
test_that("handle insurance correctly maps insurance", {
result <- sapply(c("% insured in demographic group, all income levels",
"% uninsured in demographic group, all income levels",
"% insured in demographic group, people at or below 138% of poverty"),
handle_insurance)
expected <- c(`% insured in demographic group, all income levels` = "00030",
`% uninsured in demographic group, all income levels` = "00040",
`% insured in demographic group, people at or below 138% of poverty` = "00033")

expect_equal(result, expected)
})

test_that("handle insurance expects errors for incorrect arguments", {
expect_error(handle_insurance("carrot"))
})
17 changes: 17 additions & 0 deletions tests/testthat/test-handle-mobility.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' Test Handle mobility
#'
#' This testthat file tests the handle-mobility function
test_that("handle mobility correctly maps mobility", {
result <- sapply(c("i haven't moved (in past year)",
"moved from outside us (in past year)",
"moved, same county (in past year)"), handle_mobility)
expected <- c(`i haven't moved (in past year)` = "00017",
`moved from outside us (in past year)` = "00021",
`moved, same county (in past year)` = "00018")

expect_equal(result, expected)
})

test_that("handle mobility expects errors for incorrect arguments", {
expect_error(handle_mobility("carrot"))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-handle-population.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Test Handle population
#'
#' This testthat file tests the handle-population function
test_that("handle population correctly maps population", {
result <- sapply(c("age under 18", "foreign born", "males"), handle_population)
expected <- c(`age under 18` = "00002", `foreign born` = "00014", `males` = "00104")

expect_equal(result, expected)
})

test_that("handle population expects errors for incorrect arguments", {
expect_error(handle_population("carrot"))
})
15 changes: 15 additions & 0 deletions tests/testthat/test-handle-poverty.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' Test Handle poverty
#'
#' This testthat file tests the handle-poverty function
test_that("handle poverty correctly maps poverty", {
result <- sapply(c("families below poverty", "persistent poverty",
"persons below poverty"), handle_poverty)
expected <- c(`families below poverty` = "00007", `persistent poverty` = "03001",
`persons below poverty` = "00008")

expect_equal(result, expected)
})

test_that("handle poverty expects errors for incorrect arguments", {
expect_error(handle_poverty("carrot"))
})
16 changes: 16 additions & 0 deletions tests/testthat/test-handle-race.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Test Handle race
#'
#' This testthat file tests the handle-race function
test_that("handle race correctly maps race", {
result <- sapply(c("all races (includes hispanic)", "white (non-hispanic)",
"asian non-hispanic"), handle_race)
expected <- c(`all races (includes hispanic)` = "00",
`white (non-hispanic)` = "07",
`asian non-hispanic` = "49")

expect_equal(result, expected)
})

test_that("handle race expects errors for incorrect arguments", {
expect_error(handle_race("carrot"))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-handle-risk-datatype.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Test Handle datatype
#'
#' This testthat file tests the handle-datatype function
test_that("handle datatype correctly maps datatype", {
result <- sapply(c("direct estimates", "county level modeled estimates"), handle_datatype)
expected <- c(`direct estimates` = "0", `county level modeled estimates` = "1")

expect_equal(result, expected)
})

test_that("handle datatype expects errors for incorrect arguments", {
expect_error(handle_datatype("carrot"))
})
17 changes: 17 additions & 0 deletions tests/testthat/test-handle-screening.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' Test Handle screening
#'
#' This testthat file tests the handle-screening function
test_that("handle screening correctly maps screening", {
result <- sapply(c("ever had fobt, ages 50-75",
"guidance sufficient crc, ages 50-75",
"home blood stool test in the past year, ages 45-75"), handle_screening)
expected <- c(`ever had fobt, ages 50-75` = "v304",
`guidance sufficient crc, ages 50-75` = "v303",
`home blood stool test in the past year, ages 45-75` = "v520")

expect_equal(result, expected)
})

test_that("handle screening expects errors for incorrect arguments", {
expect_error(handle_screening("carrot"))
})
17 changes: 17 additions & 0 deletions tests/testthat/test-handle-smoking.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' Test Handle smoking
#'
#' This testthat file tests the handle-smoking function
test_that("handle smoking correctly maps age", {
result <- sapply(c("smokers (current); ages 18+",
"smokers (ever); ages 18+",
"smoking laws (any)"), handle_smoking)
expected <- c(`smokers (current); ages 18+` = "v19",
`smokers (ever); ages 18+` = "v28",
`smoking laws (any)` = "v44")

expect_equal(result, expected)
})

test_that("handle smoking expects errors for incorrect arguments", {
expect_error(handle_smoking("carrot"))
})
13 changes: 13 additions & 0 deletions tests/testthat/test-handle-stage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Test Handle stage
#'
#' This testthat file tests the handle-stage function
test_that("handle stage correctly maps stage", {
result <- sapply(c("all stages", "late stage (regional & distant)"), handle_stage)
expected <- c(`all stages` = "999", `late stage (regional & distant)` = "211")

expect_equal(result, expected)
})

test_that("handle stage expects errors for incorrect arguments", {
expect_error(handle_stage("carrot"))
})
15 changes: 15 additions & 0 deletions tests/testthat/test-handle-svi.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' Test Handle svi
#'
#' This testthat file tests the handle-svi function
test_that("handle svi correctly maps svi", {
result <- sapply(c("overall", "socioeconomic status",
"household characteristics"), handle_svi)
expected <- c(`overall` = "03010", `socioeconomic status` = "03011",
`household characteristics` = "03012")

expect_equal(result, expected)
})

test_that("handle svi expects errors for incorrect arguments", {
expect_error(handle_svi("carrot"))
})
16 changes: 16 additions & 0 deletions tests/testthat/test-handle-vaccine.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Test Handle vaccine
#'
#' This testthat file tests the handle-vaccine function
test_that("handle vaccine correctly maps vaccine", {
result <- sapply(c("percent with up to date hpv vaccination coverage, ages 13-15",
"percent with up to date hpv vaccination coverage, ages 13-17"),
handle_vaccine)
expected <- c(`percent with up to date hpv vaccination coverage, ages 13-15` = "v281",
`percent with up to date hpv vaccination coverage, ages 13-17` = "v282")

expect_equal(result, expected)
})

test_that("handle vaccine expects errors for incorrect arguments", {
expect_error(handle_vaccine("carrot"))
})
18 changes: 18 additions & 0 deletions tests/testthat/test-handle-whealth.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' Test Handle Women's Health
#'
#' This testthat file tests the handle-whealth function
test_that("handle whealth correctly maps whealth", {
result <- sapply(c("mammogram in past 2 years, ages 50-74",
"mammogram in past 2 years, ages 40+",
"pap smear in past 3 years, no hysterectomy, ages 21-65"),
handle_whealth)
expected <- c(`mammogram in past 2 years, ages 50-74` = "v05",
`mammogram in past 2 years, ages 40+` = "v06",
`pap smear in past 3 years, no hysterectomy, ages 21-65` = "v17")

expect_equal(result, expected)
})

test_that("handle whealth expects errors for incorrect arguments", {
expect_error(handle_whealth("carrot"))
})
Loading

0 comments on commit 636532b

Please sign in to comment.