Skip to content

Commit

Permalink
Merge pull request #25 from getwilds/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
realbp authored Feb 13, 2024
2 parents 9be4f42 + 0f5a6fc commit 6535c98
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 45 deletions.
13 changes: 9 additions & 4 deletions R/handle-screening.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ handle_screening <- function(screening) {
screening <- tolower(screening)

screening_mapping <- c(
"ever had colorectal endoscopy (sigmoidoscopy or colonoscopy), ages 50+" = "v09",
"ever had fobt, ages 50-75" = "v304",
"fobt (1yr) / flex sig (5yr) / fobt (3yr) / colonoscopy (10yr), ages 50-75" = "v14",
"guidance sufficient crc, ages 50-75" = "v303",
"had colonoscopy in past 10 years, ages 50-75" = "v302",
"home-based fecal occult blood test (fobt) in past two years" = "v13",
"home-based fobt in the past two years or ever had a colorectal endoscopy" = "v59"

"home blood stool test in the past year, ages 45-75" = "v520",
"receieved at least one recommended crc test, ages 45-75" = "v521"

#removed from scp
# "ever had colorectal endoscopy (sigmoidoscopy or colonoscopy), ages 50+" = "v09",
# "fobt (1yr) / flex sig (5yr) / fobt (3yr) / colonoscopy (10yr), ages 50-75" = "v14",
# "home-based fecal occult blood test (fobt) in past two years" = "v13",
# "home-based fobt in the past two years or ever had a colorectal endoscopy" = "v59"
)

screening_code <- screening_mapping[screening]
Expand Down
18 changes: 8 additions & 10 deletions R/risk-colorectal-screening.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#'
#' This function returns a data frame from Colorectal Screening in State Cancer Profiles
#'
#' @param screening One of the following values: "ever had colorectal endoscopy (sigmoidoscopy or colonoscopy), ages 50+",
#' "fobt (1yr) / flex sig (5yr) / fobt (3yr) / colonoscopy (10yr), ages 50-75",
#' "home-based fecal occult blood test (fobt) in past two years",
#' "home-based fobt in the past two years or ever had a colorectal endoscopy", "ever had fobt, ages 50-75",
#' "guidance sufficient crc, ages 50-75", "had colonoscopy in past 10 years, ages 50-75"
#' @param screening One of the following values: "home blood stool test in the past year, ages 45-75",
#' "receieved at least one recommended crc test, ages 45-75",
#' "ever had fobt, ages 50-75",
#' "guidance sufficient crc, ages 50-75",
#' "had colonoscopy in past 10 years, ages 50-75"
#' @param race One of the following values: "All Races (includes Hispanic)", "white (includes hispanic)",
#' "white non-hispanic","black","amer. indian/alaskan native (includes hispanic)",
#' "asian or pacific islander (includes hispanic)","hispanic (any race)
Expand All @@ -19,7 +19,7 @@
#'
#' @examples
#' \dontrun{
#' risk_colorectal_screening("ever had colorectal endoscopy (sigmoidoscopy or colonoscopy), ages 50+",
#' risk_colorectal_screening("home blood stool test in the past year, ages 45-75",
#' "all races (includes hispanic)","both sexes")
#' risk_colorectal_screening("ever had fobt, ages 50-75", area="usa")
#' risk_colorectal_screening("ever had fobt, ages 50-75", area="wa")
Expand All @@ -28,10 +28,8 @@ risk_colorectal_screening <- function(screening, race=NULL, sex=NULL, area=NULL)

req <- create_request("risk")

screening_type_1 = c("ever had colorectal endoscopy (sigmoidoscopy or colonoscopy), ages 50+",
"fobt (1yr) / flex sig (5yr) / fobt (3yr) / colonoscopy (10yr), ages 50-75",
"home-based fecal occult blood test (fobt) in past two years",
"home-based fobt in the past two years or ever had a colorectal endoscopy")
screening_type_1 = c("home blood stool test in the past year, ages 45-75",
"receieved at least one recommended crc test, ages 45-75")

screening_type_2 = c("ever had fobt, ages 50-75",
"guidance sufficient crc, ages 50-75",
Expand Down
12 changes: 10 additions & 2 deletions R/risk-diet-exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ risk_diet_exercise <- function(diet_exercise, race, sex) {

resp <- process_screening(resp)

resp %>%
setNames(c("State", "FIPS", "Percent", "Lower_95%_CI", "Upper_95%_CI", "Number_of_Respondents"))
diet_exercise_type1 = c("bmi is overweight, high school survey",
"bmi is obese, high school survey")

if (diet_exercise %in% diet_exercise_type1) {
resp %>%
setNames(c("State", "FIPS", "Percent", "Lower_95%_CI", "Upper_95%_CI"))
} else {
resp %>%
setNames(c("State", "FIPS", "Percent", "Lower_95%_CI", "Upper_95%_CI", "Number_of_Respondents"))
}
}
12 changes: 6 additions & 6 deletions man/risk_colorectal_screening.Rd

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

44 changes: 25 additions & 19 deletions tests/testthat/test-demo-crowding.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
# test_that("demo-crowding", {
# test_crowding1 <- demo_crowding("WA", "hsa", "All Races (includes Hispanic)")
#
#
# # object, length, dimensions,
# # ranges -ex: greater than 10 rows
# # errors
#
#
# #expect_error() - catches an expected error
# })


#' Test demo-crowding
#'
#' This testthat file test the demo-crowding function
#'
#tests class and typeof output
test_that("Output data type is correct", {
output <- demo_crowding("usa", "state", "All Races (includes Hispanic)")

expect_equal(class(output), "data.frame",
info = "Output should be a data frame")
output <- demo_crowding("wa", "hsa", "All Races (includes Hispanic)")

expect_equal(typeof(output), "list",
info = "Output should have list storage type (since data frames are lists)")
expect_true(inherits(output, "data.frame"))
})

#Ensures that variables are present and working on SCP
test_that("demo-crowding returns non-empty data frame", {
crowding1 <- demo_crowding("wa", "hsa", "All Races (includes Hispanic)")
expect_true(is.data.frame(crowding1))
})

#demo-crowding must have 5 columns
test_that("demo-crowding has correct number of columns", {
df <- demo_crowding("wa", "hsa", "All Races (includes Hispanic)")
expected_columns <- 5
expect_equal(ncol(df), expected_columns)
})

#parameter
test_that("demo-crowding has correct parameters", {
expect_error(demo_crowding())
})
8 changes: 4 additions & 4 deletions tests/testthat/test-demo-poverty.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ test_that("Output data type is correct", {

#Ensures that variables are present and working on SCP
poverty_options <- list(
pov1 <- demo_poverty("wa", "county", "persistent poverty"),
pov2 <- demo_poverty("wa", "county", "families below poverty", "black"),
pov3 <- demo_poverty("wa", "county", "persons below poverty", "black", "both sexes"),
pov4 <- demo_poverty("wa", "county", "persons < 150% of poverty")
pov1 = demo_poverty("wa", "county", "persistent poverty"),
pov2 = demo_poverty("wa", "county", "families below poverty", "black"),
pov3 = demo_poverty("wa", "county", "persons below poverty", "black", "both sexes"),
pov4 = demo_poverty("wa", "county", "persons < 150% of poverty")
)

for (option_name in names(poverty_options)) {
Expand Down
34 changes: 34 additions & 0 deletions tests/testthat/test-risk-alcohol.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Test risk-alcohol
#'
#' This testthat file test the risk-alcohol function
#'
#tests class and typeof output
test_that("Output data type is correct", {
output <- risk_alcohol(paste("binge drinking (4+ drinks on one occasion for women,",
"5+ drinks for one occasion for men), ages 21+"),
"all races (includes hispanic)", "both sexes")

expect_true(inherits(output, "data.frame"))
})

#Ensures that variables are present and working on SCP
test_that("risk-alcohol returns non-empty data frame", {
alcohol1 <- risk_alcohol(paste("binge drinking (4+ drinks on one occasion for women,",
"5+ drinks for one occasion for men), ages 21+"),
"all races (includes hispanic)", "both sexes")
expect_true(is.data.frame(alcohol1))
})

#risk-alcohol must have 5 columns
test_that("risk-alcohol has correct number of columns", {
df <- risk_alcohol(paste("binge drinking (4+ drinks on one occasion for women,",
"5+ drinks for one occasion for men), ages 21+"),
"all races (includes hispanic)", "both sexes")
expected_columns <- 6
expect_equal(ncol(df), expected_columns)
})

#parameter
test_that("risk-alcohol has correct parameters", {
expect_error(demo_alcohol())
})
57 changes: 57 additions & 0 deletions tests/testthat/test-risk-colorectal-screening.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#' Test risk-colorectal-screening
#'
#' This testthat file test the risk-colorectal-screening function
#'
#tests class and typeof output
test_that("Output data type is correct", {
output <- risk_colorectal_screening("ever had fobt, ages 50-75", area="wa")

expect_true(inherits(output, "data.frame"))
})

#Ensures that variables are present and working on SCP
screening_options <- list(
screening1 = risk_colorectal_screening("ever had fobt, ages 50-75", area = "wa"),
screening2 = risk_colorectal_screening("guidance sufficient crc, ages 50-75", area = "wa"),
screening3 = risk_colorectal_screening("had colonoscopy in past 10 years, ages 50-75", area = "wa"),
screening4 = risk_colorectal_screening("home blood stool test in the past year, ages 45-75",
"all races (includes hispanic)", "both sexes"),
screening5 = risk_colorectal_screening("receieved at least one recommended crc test, ages 45-75",
"all races (includes hispanic)", "both sexes")
)

for (option_name in names(screening_options)) {
test_that("risk-colorectal-screening returns non-empty data frame", {
option <- screening_options[[option_name]]
expect_true(is.data.frame(option))
})
}

#risk-colorectal-screening must have 5 columns
test_that("risk-colorectal-screening has correct number of columns", {
df1 <- risk_colorectal_screening("ever had fobt, ages 50-75", area="wa")
df2 <- risk_colorectal_screening("home blood stool test in the past year, ages 45-75",
"all races (includes hispanic)","both sexes")
expected_columns1 <- 5
expected_columns2 <- 6
expect_equal(ncol(df1), expected_columns1)
expect_equal(ncol(df2), expected_columns2)
})

#test error handling
test_that("risk-colorectal-screening handles invalid colorectal_screening parameters", {
expect_error(
risk_colorectal_screening("ever had fobt, ages 50-75", race="all races (includes hispanic)"),
"for this screening type, area must NOT be NULL and Race and Sex must be NULL"
)
expect_error(
risk_colorectal_screening("home blood stool test in the past year, ages 45-75",
"all races (includes hispanic)"),
"For this screening type, Race and Sex must not be NULL"
)
})

#parameter
test_that("risk-colorectal-screening has correct parameters", {
expect_error(risk_colorectal_screening())
})
42 changes: 42 additions & 0 deletions tests/testthat/test-risk-diet-exercise.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' Test risk-diet-exercise
#'
#' This testthat file test the risk-diet-exercise function
#'
#tests class and typeof output
test_that("Output data type is correct", {
output <- risk_diet_exercise("bmi is healthy, ages 20+",
"all races (includes hispanic)", "both sexes")

expect_true(inherits(output, "data.frame"))
})

#Ensures that variables are present and working on SCP
diet_exercise_options <- c("bmi is healthy, ages 20+", "bmi is obese, ages 20+",
"bmi is obese, high school survey", "bmi is overweight, high school survey",
"consumed 1 or more fruits per day", "consumed 1 or more vegetables per day",
"no leisure time physical activity")

for (option in diet_exercise_options) {
test_that("risk_diet_exercise returns non-empty data frame", {
result <- risk_diet_exercise(option, "all races (includes hispanic)", "both sexes")
expect_true(is.data.frame(result))
})
}

#risk-diet-exercise must have 5 columns
test_that("risk-diet-exercise has correct number of columns", {
df1 <- risk_diet_exercise("bmi is healthy, ages 20+",
"all races (includes hispanic)", "both sexes")
df2 <- risk_diet_exercise("bmi is obese, high school survey",
"all races (includes hispanic)", "males")
expected_columns1 <- 6
expected_columns2 <- 5
expect_equal(ncol(df1), expected_columns1)
expect_equal(ncol(df2), expected_columns2)

})

#parameter
test_that("risk-diet-exercise has correct parameters", {
expect_error(risk_diet_exercise())
})
3 changes: 3 additions & 0 deletions tests/testthat/test-risk-smoking.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})
3 changes: 3 additions & 0 deletions tests/testthat/test-risk-vaccines.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})
42 changes: 42 additions & 0 deletions tests/testthat/test-risk-womens-health.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' Test risk-womens health
#'
#' This testthat file test the risk-womens health function
#'
#tests class and typeof output
# test_that("Output data type is correct", {
# output <- risk_womens_health("bmi is healthy, ages 20+",
# "all races (includes hispanic)", "both sexes")
#
# expect_true(inherits(output, "data.frame"))
# })
#
# #Ensures that variables are present and working on SCP
# womens_health_options <- c("bmi is healthy, ages 20+", "bmi is obese, ages 20+",
# "bmi is obese, high school survey", "bmi is overweight, high school survey",
# "consumed 1 or more fruits per day", "consumed 1 or more vegetables per day",
# "no leisure time physical activity")
#
# for (option in womens_health_options) {
# test_that("risk_womens_health returns non-empty data frame", {
# result <- risk_womens_health(option, "all races (includes hispanic)", "both sexes")
# expect_true(is.data.frame(result))
# })
# }
#
# #risk-womens health must have 5 columns
# test_that("risk-womens health has correct number of columns", {
# df1 <- risk_womens_health("bmi is healthy, ages 20+",
# "all races (includes hispanic)", "both sexes")
# df2 <- risk_womens_health("bmi is obese, high school survey",
# "all races (includes hispanic)", "males")
# expected_columns1 <- 6
# expected_columns2 <- 5
# expect_equal(ncol(df1), expected_columns1)
# expect_equal(ncol(df2), expected_columns2)
#
# })
#
# #parameter
# test_that("risk-womens health has correct parameters", {
# expect_error(risk_womens_health())
# })

0 comments on commit 6535c98

Please sign in to comment.