diff --git a/tests/testthat/test-incidence-cancer.R b/tests/testthat/test-incidence-cancer.R index 4ee1971..4c0525b 100644 --- a/tests/testthat/test-incidence-cancer.R +++ b/tests/testthat/test-incidence-cancer.R @@ -108,6 +108,20 @@ test_that("incidence_cancer has correct number of columns", { expect_equal(ncol(df2), expected_columns2) }) +#test error handling +test_that("incidence_cancer handles invalid cancer parameters", { + expect_error( + incidence_cancer("wa", "county", "all cancer sites", "black (non-hispanic)", + "both sexes", "ages 65+", "late stage (regional & distant)"), + "For this cancer type, stage must be all stages" + ) + expect_error( + incidence_cancer("ca", "hsa", "prostate", "all races (includes hispanic)", "both sexes", + "ages 50+", "all stages"), + "For prostate cancer, sex must be males." + ) +}) + # parameter test_that("incidence_cancer has correct parameters", { expect_error(incidence_cancer()) diff --git a/tests/testthat/test-mortality-cancer.R b/tests/testthat/test-mortality-cancer.R index df1a9bd..67cf033 100644 --- a/tests/testthat/test-mortality-cancer.R +++ b/tests/testthat/test-mortality-cancer.R @@ -105,7 +105,23 @@ test_that("mortality_cancer has correct number of columns", { expect_equal(ncol(df), expected_columns) }) -# parameter +#test error handling +test_that("mortality_cancer handles invalid cancer parameters", { + expect_error( + mortality_cancer(area="wa", areatype="county", cancer="ovary", + race="all races (includes hispanic)", + sex="both sexes", age="ages 50+"), + "For this cancer type, sex must be females" + ) + expect_error( + mortality_cancer("usa", "state", "prostate", "all races (includes hispanic)", + "both sexes", "ages 50+"), + "For prostate cancer, sex must be males." + ) +}) + +#parameter test_that("mortality_cancer has correct parameters", { expect_error(mortality_cancer()) }) +