From 807ed35cb7042a3e08df0db622cee0147122b2b1 Mon Sep 17 00:00:00 2001 From: Jared Knowles Date: Wed, 29 Apr 2026 17:17:52 -0400 Subject: [PATCH] test(peers): per-year cohort expectations (failing) Three RED tests that drive Task 6's cog_find_peers() rewrite: - defaults year to most recent observed (expects cohort_year attr + population column) - honors explicit year= argument (expects cohort_year attr) - errors with "no observed population" for unobserved year --- tests/testthat/test-peers.R | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/testthat/test-peers.R b/tests/testthat/test-peers.R index 00612dc..f393cb6 100644 --- a/tests/testthat/test-peers.R +++ b/tests/testthat/test-peers.R @@ -88,3 +88,26 @@ test_that("cog_peer_compare handles zero peers gracefully", { expect_true(all(r$role == "target")) expect_equal(sum(grepl("^summary_", r$role)), 0L) }) + +test_that("cog_find_peers defaults `year` to most recent observed year for target", { + skip_if_no_corpus() + peers <- cog_find_peers("101006006") + expect_equal(attr(peers, "cohort_year"), 2020L) + # Returned column is now `population`, not `population_acs` + expect_true("population" %in% names(peers)) + expect_false("population_acs" %in% names(peers)) +}) + +test_that("cog_find_peers honors an explicit `year`", { + skip_if_no_corpus() + peers <- cog_find_peers("101006006", year = 2019L) + expect_equal(attr(peers, "cohort_year"), 2019L) +}) + +test_that("cog_find_peers errors when target has no observed pop in `year`", { + skip_if_no_corpus() + expect_error( + cog_find_peers("101006006", year = 1999L), + "no observed population" + ) +})