From 8bc96b63f6bce7f278ad5d69617fc4e37479790c Mon Sep 17 00:00:00 2001 From: avahoffman Date: Fri, 28 Jun 2024 00:03:42 -0400 Subject: [PATCH] UNIT TESTS! --- tests/testthat/test-CO_heat_ER.R | 68 +++++++++++++++++ tests/testthat/test-calenviroscreen.R | 85 ++++++++++++++++++++-- tests/testthat/test-covid_wastewater.R | 28 +++++++ tests/testthat/test-er_CO.R | 20 +++++ tests/testthat/test-haa5.R | 27 +++++++ tests/testthat/test-nitrate.R | 27 +++++++ tests/testthat/test-yearly_co2_emissions.R | 12 +++ 7 files changed, 262 insertions(+), 5 deletions(-) create mode 100644 tests/testthat/test-CO_heat_ER.R create mode 100644 tests/testthat/test-covid_wastewater.R create mode 100644 tests/testthat/test-er_CO.R create mode 100644 tests/testthat/test-haa5.R create mode 100644 tests/testthat/test-nitrate.R create mode 100644 tests/testthat/test-yearly_co2_emissions.R diff --git a/tests/testthat/test-CO_heat_ER.R b/tests/testthat/test-CO_heat_ER.R new file mode 100644 index 0000000..3b3ee17 --- /dev/null +++ b/tests/testthat/test-CO_heat_ER.R @@ -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" + ) + ) +}) diff --git a/tests/testthat/test-calenviroscreen.R b/tests/testthat/test-calenviroscreen.R index 680a3be..d6481e5 100644 --- a/tests/testthat/test-calenviroscreen.R +++ b/tests/testthat/test-calenviroscreen.R @@ -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" + ) ) }) diff --git a/tests/testthat/test-covid_wastewater.R b/tests/testthat/test-covid_wastewater.R new file mode 100644 index 0000000..12f15bc --- /dev/null +++ b/tests/testthat/test-covid_wastewater.R @@ -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" + ) + ) +}) diff --git a/tests/testthat/test-er_CO.R b/tests/testthat/test-er_CO.R new file mode 100644 index 0000000..a386e5f --- /dev/null +++ b/tests/testthat/test-er_CO.R @@ -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") + ) +}) diff --git a/tests/testthat/test-haa5.R b/tests/testthat/test-haa5.R new file mode 100644 index 0000000..8cacf7e --- /dev/null +++ b/tests/testthat/test-haa5.R @@ -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" + ) + ) +}) diff --git a/tests/testthat/test-nitrate.R b/tests/testthat/test-nitrate.R new file mode 100644 index 0000000..4ca76d0 --- /dev/null +++ b/tests/testthat/test-nitrate.R @@ -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" + ) + ) +}) diff --git a/tests/testthat/test-yearly_co2_emissions.R b/tests/testthat/test-yearly_co2_emissions.R new file mode 100644 index 0000000..82d204f --- /dev/null +++ b/tests/testthat/test-yearly_co2_emissions.R @@ -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)))) +})