From 4de9a36b11d848165aa2350a3ba12c7e7352825e Mon Sep 17 00:00:00 2001 From: realbp Date: Thu, 22 Feb 2024 13:16:28 -0800 Subject: [PATCH] added error tests --- tests/testthat/test-incidence-cancer.R | 17 +++++++++++++++-- tests/testthat/test-mortality-cancer.R | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-incidence-cancer.R b/tests/testthat/test-incidence-cancer.R index c7d401c..f3181d6 100644 --- a/tests/testthat/test-incidence-cancer.R +++ b/tests/testthat/test-incidence-cancer.R @@ -63,10 +63,23 @@ test_that("incidence_cancer has correct number of columns", { expected_columns2 <- 10 expect_equal(ncol(df1), expected_columns1) 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()) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-mortality-cancer.R b/tests/testthat/test-mortality-cancer.R index 71efb4d..4af2b70 100644 --- a/tests/testthat/test-mortality-cancer.R +++ b/tests/testthat/test-mortality-cancer.R @@ -59,7 +59,23 @@ test_that("mortality_cancer has correct number of columns", { }) +#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()) -}) \ No newline at end of file +}) +