Skip to content

Commit

Permalink
UNIT TESTS!
Browse files Browse the repository at this point in the history
  • Loading branch information
avahoffman committed Jun 28, 2024
1 parent a77ab4d commit 8bc96b6
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 5 deletions.
68 changes: 68 additions & 0 deletions tests/testthat/test-CO_heat_ER.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
test_that("Is non-empty tibble", {
expect_false(dim(CO_heat_ER)[1] == 0)
expect_false(dim(CO_heat_ER)[2] == 0)
expect_false(dim(CO_heat_ER_byage)[1] == 0)
expect_false(dim(CO_heat_ER_byage)[2] == 0)
expect_false(dim(CO_heat_ER_bygender)[1] == 0)
expect_false(dim(CO_heat_ER_bygender)[2] == 0)
expect_false(dim(CO_heat_ER_long)[1] == 0)
expect_false(dim(CO_heat_ER_long)[2] == 0)
expect_false(dim(CO_heat_ER_wide)[1] == 0)
expect_false(dim(CO_heat_ER_wide)[2] == 0)
})

test_that("Is tibble", {
expect_s3_class(CO_heat_ER, 'tbl_df')
expect_s3_class(CO_heat_ER_byage, 'tbl_df')
expect_s3_class(CO_heat_ER_bygender, 'tbl_df')
expect_s3_class(CO_heat_ER_long, 'tbl_df')
expect_s3_class(CO_heat_ER_wide, 'tbl_df')
})

test_that("Column names are correct", {
expect_named(
CO_heat_ER,
c(
"county",
"rate",
"lower95cl",
"upper95cl",
"visits",
"year",
"gender"
)
)
expect_named(CO_heat_ER_byage,
c("YEAR", "GENDER", "AGE", "RATE", "L95CL", "U95CL", "VISITS"))
expect_named(
CO_heat_ER_bygender,
c(
"county",
"rate",
"lower95cl",
"upper95cl",
"visits",
"year",
"gender"
)
)
expect_named(CO_heat_ER_long, c("county", "rate", "year"))
expect_named(
CO_heat_ER_wide,
c(
"county",
"2011",
"2012",
"2013",
"2014",
"2015",
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022"
)
)
})
85 changes: 80 additions & 5 deletions tests/testthat/test-calenviroscreen.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,83 @@
test_that("Is non-empty tibble", {
expect_false(
dim(calenviroscreen)[1] == 0
)
expect_false(
dim(calenviroscreen)[2] == 0
expect_false(dim(calenviroscreen)[1] == 0)
expect_false(dim(calenviroscreen)[2] == 0)
})

test_that("Is tibble", {
expect_s3_class(calenviroscreen, 'tbl_df')
})

test_that("Column names are correct", {
expect_named(
calenviroscreen,
c(
"CensusTract",
"CaliforniaCounty",
"ZIP",
"Longitude",
"Latitude",
"ApproxLocation",
"CES4.0Score",
"CES4.0Percentile",
"CES4.0PercRange",
"Ozone",
"OzonePctl",
"PM2.5",
"PM2.5.Pctl",
"DieselPM",
"DieselPMPctl",
"DrinkingWater",
"DrinkingWaterPctl",
"Lead",
"LeadPctl",
"Pesticides",
"PesticidesPctl",
"ToxRelease",
"ToxReleasePctl",
"Traffic",
"TrafficPctl",
"CleanupSites",
"CleanupSitesPctl",
"GroundwaterThreats",
"GroundwaterThreatsPctl",
"HazWaste",
"HazWastePctl",
"ImpWaterBodies",
"ImpWaterBodiesPctl",
"SolidWaste",
"SolidWastePctl",
"PollutionBurden",
"PollutionBurdenScore",
"PollutionBurdenPctl",
"Asthma",
"AsthmaPctl",
"LowBirthWeight",
"LowBirthWeightPctl",
"CardiovascularDisease",
"CardiovascularDiseasePctl",
"TotalPop",
"ChildrenPercLess10",
"PopPerc10to64",
"ElderlyMore64",
"HispanicPerc",
"WhitePerc",
"AfAmericanPerc",
"NativeAmericanPerc",
"AsianAmericanPerc",
"OtherMultiplePerc",
"PopChar",
"PopCharScore",
"PopCharPctl",
"Education",
"EducationPctl",
"LinguisticIsol",
"LinguisticIsolPctl",
"Poverty",
"PovertyPctl",
"Unemployment",
"UnemploymentPctl",
"HousingBurden",
"HousingBurdenPctl"
)
)
})
28 changes: 28 additions & 0 deletions tests/testthat/test-covid_wastewater.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
test_that("Is non-empty tibble", {
expect_false(dim(covid_wastewater)[1] == 0)
expect_false(dim(covid_wastewater)[2] == 0)
})

test_that("Is tibble", {
expect_s3_class(covid_wastewater, 'tbl_df')
})

test_that("Column names are correct", {
expect_named(
covid_wastewater,
c(
"reporting_jurisdiction",
"sample_location",
"key_plot_id",
"county_names",
"population_served",
"date_start",
"date_end",
"rna_pct_change_15d",
"pos_PCR_prop_15d",
"percentile",
"sampling_prior",
"first_sample_date"
)
)
})
20 changes: 20 additions & 0 deletions tests/testthat/test-er_CO.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test_that("Is non-empty tibble", {
expect_false(dim(er_CO_statewide)[1] == 0)
expect_false(dim(er_CO_statewide)[2] == 0)
expect_false(dim(er_visits_by_CO_county)[1] == 0)
expect_false(dim(er_visits_by_CO_county)[2] == 0)
})

test_that("Is tibble", {
expect_s3_class(er_CO_statewide, 'tbl_df')
expect_s3_class(er_visits_by_CO_county, 'tbl_df')
})

test_that("Column names are correct", {
expect_named(er_CO_statewide,
c("rate", "lower95cl", "upper95cl", "visits", "year"))
expect_named(
er_visits_by_CO_county,
c("county", "rate", "lower95cl", "upper95cl", "visits", "year")
)
})
27 changes: 27 additions & 0 deletions tests/testthat/test-haa5.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
test_that("Is non-empty tibble", {
expect_false(dim(haa5)[1] == 0)
expect_false(dim(haa5)[2] == 0)
})

test_that("Is tibble", {
expect_s3_class(haa5, 'tbl_df')
})

test_that("Column names are correct", {
expect_named(
haa5,
c(
"year",
"pop_on_sampled_PWS",
"pop_0-15µg/L",
"pop_>15-30µg/L",
"pop_>30-45µg/L",
"pop_>45-60µg/L",
"pop_>60-75µg/L",
"pop_>75µg/L",
"pop_on_PWS_with_non-detects",
"pop_exposed_to_exceedances",
"perc_pop_exposed_to_exceedances"
)
)
})
27 changes: 27 additions & 0 deletions tests/testthat/test-nitrate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
test_that("Is non-empty tibble", {
expect_false(dim(nitrate)[1] == 0)
expect_false(dim(nitrate)[2] == 0)
})

test_that("Is tibble", {
expect_s3_class(nitrate, 'tbl_df')
})

test_that("Column names are correct", {
expect_named(
nitrate,
c(
"year",
"quarter",
"pop_on_sampled_PWS",
"pop_0-3ug/L",
"pop_>3-5ug/L",
"pop_>5-10ug/L",
"pop_>10-20ug/L",
"pop_>20ug/L",
"pop_on_PWS_with_non-detect",
"pop_exposed_to_exceedances",
"perc_pop_exposed_to_exceedances"
)
)
})
12 changes: 12 additions & 0 deletions tests/testthat/test-yearly_co2_emissions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("Is non-empty tibble", {
expect_false(dim(yearly_co2_emissions)[1] == 0)
expect_false(dim(yearly_co2_emissions)[2] == 0)
})

test_that("Is tibble", {
expect_s3_class(yearly_co2_emissions, 'tbl_df')
})

test_that("Column names are correct", {
expect_named(yearly_co2_emissions, c("country", as.character(seq(1751, 2014))))
})

0 comments on commit 8bc96b6

Please sign in to comment.