test: re-baseline canonical_govid literals to 12-char namespace
Swaps every hardcoded 9-char canonical_govid literal (Broward County,
Fort Lauderdale City, Florida/Alabama state govts, Bexar/Tarrant/Wayne
counties, San Diego/Oakland/Miami/Austin cities) for its 12-char Phase P
equivalent, resolved by name+type+state against the regenerated fixture
xwalk. Also updates two gov_name search patterns that no longer match
under Phase P canonical naming ("FLORIDA STATE GOVT" -> "FLORIDA"; the
"Miami" substring test now pins type = "city" since MIAMI-DADE COUNTY's
canonical name now also contains "Miami", which would otherwise make the
match ambiguous across govs_types instead of resolving via largest-pop).
Underlying per-year population figures for Broward County and Alabama
are unchanged, so no expected data-value literals needed recomputation.
Suite: 126 test blocks / 336 expectations, 0 FAIL / 0 WARN / 0 SKIP.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
test_that("cog_spending returns expected shape for Broward Corrections 2020", {
|
||||
skip_if_no_corpus()
|
||||
r <- cog_spending("101006006", years = 2020L, category = "Corrections")
|
||||
r <- cog_spending("121011212191", years = 2020L, category = "Corrections")
|
||||
expect_s3_class(r, "tbl_df")
|
||||
expected_cols <- c("year", "canonical_govid", "gov_name", "spend_subtype",
|
||||
"category", "amt_nominal", "codes_included",
|
||||
"aggregate_fallback", "notes")
|
||||
expect_true(all(expected_cols %in% names(r)))
|
||||
expect_equal(unique(r$canonical_govid), "101006006")
|
||||
expect_equal(unique(r$canonical_govid), "121011212191")
|
||||
expect_equal(unique(r$year), 2020L)
|
||||
expect_equal(unique(r$category), "Corrections")
|
||||
expect_true(all(r$spend_subtype %in% c("operations", "capital")))
|
||||
@@ -15,7 +15,7 @@ test_that("cog_spending returns expected shape for Broward Corrections 2020", {
|
||||
|
||||
test_that("cog_spending vectorised years + categories", {
|
||||
skip_if_no_corpus()
|
||||
r <- cog_spending("101006006", 2019:2020,
|
||||
r <- cog_spending("121011212191", 2019:2020,
|
||||
category = c("Corrections", "Police"))
|
||||
expect_true(all(r$year %in% 2019:2020))
|
||||
expect_true(all(r$category %in% c("Corrections", "Police")))
|
||||
@@ -24,7 +24,7 @@ test_that("cog_spending vectorised years + categories", {
|
||||
|
||||
test_that("cog_spending with per_capita adds per-capita nominal column", {
|
||||
skip_if_no_corpus()
|
||||
r <- cog_spending("101006006", 2020L, "Corrections", per_capita = TRUE)
|
||||
r <- cog_spending("121011212191", 2020L, "Corrections", per_capita = TRUE)
|
||||
expect_true("amt_per_capita_nominal" %in% names(r))
|
||||
expect_false("amt_real" %in% names(r))
|
||||
expect_false("amt_per_capita_real" %in% names(r))
|
||||
@@ -34,7 +34,7 @@ test_that("cog_spending with per_capita adds per-capita nominal column", {
|
||||
|
||||
test_that("cog_spending with adjust_to_year adds real column", {
|
||||
skip_if_no_corpus()
|
||||
r <- cog_spending("101006006", 2019:2020, "Corrections",
|
||||
r <- cog_spending("121011212191", 2019:2020, "Corrections",
|
||||
adjust_to_year = 2022L)
|
||||
expect_true("amt_real" %in% names(r))
|
||||
r2019 <- dplyr::filter(r, year == 2019L)
|
||||
@@ -43,7 +43,7 @@ test_that("cog_spending with adjust_to_year adds real column", {
|
||||
|
||||
test_that("cog_spending with per_capita + adjust_to_year adds all columns", {
|
||||
skip_if_no_corpus()
|
||||
r <- cog_spending("101006006", 2020L, "Corrections",
|
||||
r <- cog_spending("121011212191", 2020L, "Corrections",
|
||||
per_capita = TRUE, adjust_to_year = 2022L)
|
||||
expect_true(all(c("amt_nominal", "amt_real",
|
||||
"amt_per_capita_nominal", "amt_per_capita_real") %in%
|
||||
@@ -68,16 +68,16 @@ test_that("cog_spending for unknown govid returns empty tibble + informs", {
|
||||
test_that("cog_spending records found + missing govids in provenance", {
|
||||
skip_if_no_corpus()
|
||||
suppressMessages(
|
||||
r <- cog_spending(c("101006006", "XXXINVALID"), 2020L, "Corrections")
|
||||
r <- cog_spending(c("121011212191", "XXXINVALID"), 2020L, "Corrections")
|
||||
)
|
||||
prov <- attr(r, "provenance")
|
||||
expect_equal(sort(prov$scope$govids_found), "101006006")
|
||||
expect_equal(sort(prov$scope$govids_found), "121011212191")
|
||||
expect_equal(sort(prov$scope$govids_missing), "XXXINVALID")
|
||||
})
|
||||
|
||||
test_that("cog_spending result has provenance attribute matching schema", {
|
||||
skip_if_no_corpus()
|
||||
r <- cog_spending("101006006", 2020L, "Corrections")
|
||||
r <- cog_spending("121011212191", 2020L, "Corrections")
|
||||
prov <- attr(r, "provenance")
|
||||
expect_type(prov, "list")
|
||||
expect_equal(prov$verb, "cog_spending")
|
||||
@@ -93,7 +93,7 @@ test_that("cog_spending result has provenance attribute matching schema", {
|
||||
|
||||
test_that("cog_spending rejects invalid inputs", {
|
||||
expect_error(cog_spending(list(), 2020L), "character|data frame")
|
||||
expect_error(cog_spending("101006006", "2020"), "years")
|
||||
expect_error(cog_spending("121011212191", "2020"), "years")
|
||||
})
|
||||
|
||||
test_that("cog_spending accepts a cog_gov_search result directly", {
|
||||
@@ -101,12 +101,12 @@ test_that("cog_spending accepts a cog_gov_search result directly", {
|
||||
picks <- cog_gov_search("^BROWARD COUNTY$", state = "FL", type = "county")
|
||||
expect_gt(nrow(picks), 0L)
|
||||
r <- cog_spending(picks, 2020L, "Corrections")
|
||||
expect_equal(unique(r$canonical_govid), "101006006")
|
||||
expect_equal(unique(r$canonical_govid), "121011212191")
|
||||
})
|
||||
|
||||
test_that("cog_spending accepts a cog_find_peers result directly", {
|
||||
skip_if_no_corpus()
|
||||
peers <- cog_find_peers("101006006", max_peers = 3L)
|
||||
peers <- cog_find_peers("121011212191", max_peers = 3L)
|
||||
r <- cog_spending(peers, 2020L, "Police")
|
||||
expect_setequal(unique(r$canonical_govid),
|
||||
sort(peers$canonical_govid))
|
||||
@@ -132,7 +132,7 @@ test_that("cog_spending accepts a basket-mode cog_gov_search result", {
|
||||
test_that("per_capita denominator is the per-year F-33 population", {
|
||||
skip_if_no_corpus()
|
||||
with_fixture_corpus({
|
||||
r <- cog_spending("101006006", years = 2019:2020,
|
||||
r <- cog_spending("121011212191", years = 2019:2020,
|
||||
category = "Police", per_capita = TRUE)
|
||||
r_ops <- r[r$spend_subtype == "operations", ]
|
||||
# Implied denominator from amt_nominal / amt_per_capita_nominal
|
||||
@@ -140,9 +140,10 @@ test_that("per_capita denominator is the per-year F-33 population", {
|
||||
names(implied_pop) <- r_ops$year
|
||||
# Use absolute tolerance: within 1 person of per-year F-33 values.
|
||||
# Hardcoded values are Broward County's per-year Census F-33 population
|
||||
# from the bundled fixture (regenerated 2026-04-29 against cog_pipeline
|
||||
# aad34c6 + bd3e744). 1,940,907 is the static ACS 2018-2022 5-year value
|
||||
# the legacy implementation would use; we assert it is NOT what we get.
|
||||
# from the bundled fixture (regenerated 2026-07-11 against cog_pipeline
|
||||
# publish tree, pipeline_commit 1a00925, Phase P schema_version 4).
|
||||
# 1,940,907 is the static ACS 2018-2022 5-year value the legacy
|
||||
# implementation would use; we assert it is NOT what we get.
|
||||
expect_true(abs(implied_pop[["2019"]] - 1935878) < 1)
|
||||
expect_true(abs(implied_pop[["2020"]] - 1952778) < 1)
|
||||
expect_false(all(abs(implied_pop - 1940907) < 1))
|
||||
@@ -152,7 +153,7 @@ test_that("per_capita denominator is the per-year F-33 population", {
|
||||
test_that("pop_source = 'census_f33' does not produce unavailable-pop note", {
|
||||
skip_if_no_corpus()
|
||||
with_fixture_corpus({
|
||||
r <- cog_spending("101006006", years = 2019L,
|
||||
r <- cog_spending("121011212191", years = 2019L,
|
||||
category = "Police", per_capita = TRUE)
|
||||
expect_true(all(r$pop_source == "census_f33"))
|
||||
expect_true(all(is.na(r$notes) | r$notes == "" |
|
||||
@@ -177,7 +178,7 @@ test_that("aggregate fallback + unavailable pop produce concatenated notes", {
|
||||
test_that("provenance records per-year denominator metadata", {
|
||||
skip_if_no_corpus()
|
||||
with_fixture_corpus({
|
||||
r <- cog_spending("101006006", years = 2019:2020,
|
||||
r <- cog_spending("121011212191", years = 2019:2020,
|
||||
category = "Police", per_capita = TRUE)
|
||||
pc <- attr(r, "provenance")$transformations$per_capita
|
||||
expect_true(pc$applied)
|
||||
|
||||
Reference in New Issue
Block a user