Skip to content

Commit

Permalink
added skip on cran
Browse files Browse the repository at this point in the history
  • Loading branch information
realbp committed Mar 7, 2024
1 parent 444c898 commit 62df7fc
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 24 deletions.
3 changes: 3 additions & 0 deletions tests/testthat/test-demo-crowding.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_crowding(area = "wa",
areatype = "hsa",
crowding = "household with >1 person per room",
Expand All @@ -14,6 +15,7 @@ test_that("Output data type is correct", {

#Ensures that variables are present and working on SCP
test_that("demo-crowding returns non-empty data frame", {
skip_on_cran()
crowding1 <- demo_crowding(area = "wa",
areatype = "hsa",
crowding = "household with >1 person per room",
Expand All @@ -23,6 +25,7 @@ test_that("demo-crowding returns non-empty data frame", {

#demo-crowding must have 5 columns
test_that("demo-crowding has correct number of columns", {
skip_on_cran()
df <- demo_crowding(area = "wa",
areatype = "hsa",
crowding = "household with >1 person per room",
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-demo-education.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_education("wa", "county", "at least high school", "males")

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

#Ensures that variables are present and working on SCP
test_that("demo-education returns non-empty data frame", {
skip_on_cran()
education1 <- demo_education("wa", "county", "at least high school", "males")
expect_true(is.data.frame(education1))

Expand All @@ -24,6 +26,7 @@ test_that("demo-education returns non-empty data frame", {

#demo-education must have 5 columns
test_that("demo-education has correct number of columns", {
skip_on_cran()
df <- demo_education("wa", "county", "at least high school", "both sexes")
expected_columns <- 5
expect_equal(ncol(df), expected_columns)
Expand All @@ -33,6 +36,7 @@ test_that("demo-education has correct number of columns", {

#write one for error handling in education - mention in the message how values could have chnaged in SCP
test_that("demo-education handles invalid education parameters", {
skip_on_cran()
expect_error(
demo_education("wa", "county", "less than 9th grade", "males"),
"For Less than 9th Grade, Race and Sex must be NULL"
Expand Down
24 changes: 4 additions & 20 deletions tests/testthat/test-demo-food-access.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_food("wa", "county", "food insecurity", "black")

expect_equal(class(output), "data.frame",
Expand All @@ -15,6 +16,7 @@ test_that("Output data type is correct", {

#Ensures that variables are present and working on SCP
test_that("demo-food returns non-empty data frame", {
skip_on_cran()
food_test_1 <- demo_food("wa", "county", "food insecurity", "all races (includes hispanic)")
expect_true(!is.null(food_test_1))
expect_true(is.data.frame(food_test_1))
Expand All @@ -31,6 +33,7 @@ test_that("demo-food returns non-empty data frame", {
# sometimes functions will output different nuber of columns depending on variables...
# demo-food must have 5 columns
test_that("demo-food has correct number of columns", {
skip_on_cran()
df <- demo_food("wa", "county", "food insecurity", "black")
df2 <- demo_food("wa", "county", "limited access to healthy food")
expected_columns <- 3
Expand All @@ -41,6 +44,7 @@ test_that("demo-food has correct number of columns", {

#test error handling
test_that("demo-food handles invalid education parameters", {
skip_on_cran()
expect_error(
demo_food("wa", "county", "limited access to healthy food", "all races (includes hispanic)"),
"For limited access to healthy food, Race must be NULL"
Expand All @@ -54,24 +58,4 @@ test_that("demo-food handles invalid education parameters", {
#parameter
test_that("demo-food has correct parameters", {
expect_error(demo_food())
expect_error(demo_food("wa", "county", "all races (includes hispanic)", "food insecurity"))
})



















3 changes: 3 additions & 0 deletions tests/testthat/test-demo-income.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_income("wa", "county", "median family income", "all races (includes hispanic)")

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

#Ensures that variables are present and working on SCP
test_that("demo-income returns non-empty data frame", {
skip_on_cran()
income1 <- demo_income("wa", "county", "median family income", "all races (includes hispanic)")
expect_true(is.data.frame(income1))

Expand All @@ -20,6 +22,7 @@ test_that("demo-income returns non-empty data frame", {

#demo-income must have 5 columns
test_that("demo-income has correct number of columns", {
skip_on_cran()
df <- demo_income("usa", "state", "median household income", "all races (includes hispanic)")
expected_columns <- 4
expect_equal(ncol(df), expected_columns)
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-demo-insurance.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_insurance("usa", "state", "% Insured in demographic group, all income levels",
"both sexes", "under 19 years", "all races (includes hispanic)")

Expand All @@ -26,23 +27,24 @@ insurance_options <- c("% Insured in demographic group, all income levels",

for (option in insurance_options) {
test_that("demo-insurance returns non-empty data frame", {
skip_on_cran()
expect_true(is.data.frame(demo_insurance("usa", "state", option, "both sexes",
"under 19 years", "all races (includes hispanic)")))
})
}

#demo-insurance must have 5 columns
test_that("demo-insurance has correct number of columns", {
skip_on_cran()
df <- demo_insurance("wa", "hsa", "% Insured in demographic group, all income levels",
"males", "18 to 64 years")
expected_columns <- 5
expect_equal(ncol(df), expected_columns)
})

#test error handling

#write one for error handling in insurance - mention in the message how values could have chnaged in SCP
test_that("demo-insurance handles invalid insurance parameters", {
skip_on_cran()
expect_error(
demo_insurance("wa", "county", "% Insured in demographic group, all income levels",
"males", "18 to 64 years", "all races (includes hispanic)")
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-demo-mobility.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_mobility("wa", "county", "moved, different county, same state (in past year)")

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



mobility_options <- c("i haven't moved (in past year)",
"moved from outside us (in past year)",
"moved, different state (in past year)",
Expand All @@ -20,12 +19,14 @@ mobility_options <- c("i haven't moved (in past year)",

for (option in mobility_options) {
test_that("demo-mobility returns non-empty data frame", {
skip_on_cran()
expect_true(is.data.frame(demo_mobility("wa", "county", option)))
})
}

#demo-mobility must have 5 columns
test_that("demo-mobility has correct number of columns", {
skip_on_cran()
df <- demo_mobility("wa", "county", "moved, different county, same state (in past year)")
expected_columns <- 5
expect_equal(ncol(df), expected_columns)
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-demo-non-english-language.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_language("wa", "county", "language isolation")

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

#Ensures that variables are present and working on SCP
test_that("demo-language returns non-empty data frame", {
skip_on_cran()
language1 <- demo_language("wa", "county", "language isolation")
expect_true(is.data.frame(language1))
})

#demo-language must have 5 columns
test_that("demo-language has correct number of columns", {
skip_on_cran()
df <- demo_language("wa", "county", "language isolation")
expected_columns <- 5
expect_equal(ncol(df), expected_columns)
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-demo-population.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_population("WA", "county", "asian/pacific islander", sex="females")

expect_true(inherits(output, "data.frame"))
Expand All @@ -24,6 +25,7 @@ population_options <- list(

for (option_name in names(population_options)) {
test_that("demo-population returns non-empty data frame", {
skip_on_cran()
option <- population_options[[option_name]]
expect_true(is.data.frame(option))
})
Expand All @@ -34,19 +36,22 @@ race_options <- c("american indian/alaska native", "asian/pacific islander",

for (option in race_options) {
test_that("demo-population returns non-empty data frame", {
skip_on_cran()
expect_true(is.data.frame(demo_population("wa", "county", option, sex="both sexes")))
})
}

#demo-population must have 5 columns
test_that("demo-population has correct number of columns", {
skip_on_cran()
df <- demo_population("WA", "county", "asian/pacific islander", sex="females")
expected_columns <- 5
expect_equal(ncol(df), expected_columns)
})

#test error handling
test_that("demo-population handles invalid population parameters", {
skip_on_cran()
expect_error(
demo_population("wa", "county", "ages 40 and over", race="all races includes hispanic"),
"ages 40 and over and ages 50 and over, Race and Sex must be NULL"
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-demo-poverty.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_poverty("wa", "county", "persistent poverty")

expect_true(inherits(output, "data.frame"))
Expand All @@ -19,13 +20,15 @@ poverty_options <- list(

for (option_name in names(poverty_options)) {
test_that("demo-poverty returns non-empty data frame", {
skip_on_cran()
option <- poverty_options[[option_name]]
expect_true(is.data.frame(option))
})
}

#demo-poverty must have 5 columns
test_that("demo-poverty has correct number of columns", {
skip_on_cran()
df1 <- demo_poverty("wa", "county", "persistent poverty")
df2 <- demo_poverty("wa", "county", "families below poverty", "black")
expected_columns1 <- 3
Expand All @@ -36,6 +39,7 @@ test_that("demo-poverty has correct number of columns", {

#test error handling
test_that("demo-poverty handles invalid poverty parameters", {
skip_on_cran()
expect_error(
demo_poverty("wa", "hsa", "persistent poverty"),
"For persistent poverty, areatype must be county"
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-demo-svi.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_svi("wa", "overall")

expect_true(inherits(output, "data.frame"))
Expand All @@ -16,12 +17,14 @@ svi_options <- c("Overall", "socioeconomic status", "household characteristics",

for (option in svi_options) {
test_that("demo-svireturns non-empty data frame", {
skip_on_cran()
expect_true(is.data.frame(demo_svi("wa", option)))
})
}

#demo-svi must have 5 columns
test_that("demo-svi has correct number of columns", {
skip_on_cran()
df <- demo_svi("wa", "overall")
expected_columns <- 3
expect_equal(ncol(df), expected_columns)
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-demo-workforce.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- demo_workforce("wa", "county", "unemployed",
"all races (includes hispanic)", "both sexes")

Expand All @@ -12,13 +13,15 @@ test_that("Output data type is correct", {

#Ensures that variables are present and working on SCP
test_that("demo-workforce returns non-empty data frame", {
skip_on_cran()
workforce1 <- demo_workforce("wa", "county", "unemployed",
"all races (includes hispanic)", "both sexes")
expect_true(is.data.frame(workforce1))
})

#demo-workforce must have 5 columns
test_that("demo-workforce has correct number of columns", {
skip_on_cran()
df <- demo_workforce("wa", "county", "unemployed",
"all races (includes hispanic)", "both sexes")
expected_columns <- 5
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-incidence-cancer.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
# tests class and typeof output
test_that("Output data type is correct", {
skip_on_cran()
output <- incidence_cancer("wa", "county", "all cancer sites", "black (non-hispanic)",
"both sexes", "ages 65+", "all stages", "latest 5 year average")

Expand All @@ -18,6 +19,7 @@ cancer_options <- c("all cancer sites","bladder", "brain & ons", "colon & rectum

for (option in cancer_options) {
test_that("incidence cancer returns non-empty data frame", {
skip_on_cran()
result <- incidence_cancer("wa", "county", option, "all races (includes hispanic)",
"both sexes", "all ages", "all stages", "latest 5 year average")
expect_true(is.data.frame(result))
Expand All @@ -29,6 +31,7 @@ female_cancer_options <- c("breast (female)", "breast (female in situ)",

for (option in female_cancer_options) {
test_that("incidence female cancer returns non-empty data frame", {
skip_on_cran()
result <- incidence_cancer("wa", "county", option,
"all races (includes hispanic)", "females",
"ages 50+", "all stages", "latest 5 year average")
Expand All @@ -48,13 +51,15 @@ childhood_male_cancer_options <- list(

for (option_name in names(childhood_male_cancer_options)) {
test_that("incidence cancer returns non-empty data frame", {
skip_on_cran()
option <- childhood_male_cancer_options[[option_name]]
expect_true(is.data.frame(option))
})
}

#incidence_cancer must have 14 columns
test_that("incidence_cancer has correct number of columns", {
skip_on_cran()
df1 <- incidence_cancer("wa", "county", "all cancer sites", "black (non-hispanic)",
"both sexes", "ages 65+", "all stages", "latest 5 year average")
df2 <- incidence_cancer("usa", "state", "lung & bronchus", "all races (includes hispanic)", "males",
Expand Down
Loading

0 comments on commit 62df7fc

Please sign in to comment.