From 20e4ac69048334f0faad7c867bcb8f7387ada17a Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 19 Oct 2026 08:57:03 -0300 Subject: [PATCH] test: add epidemiological pipeline reference fixture --- tests/testthat/fixtures/expected-pipeline.csv | 9 +++++++++ tests/testthat/test-core-pipeline.R | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 tests/testthat/fixtures/expected-pipeline.csv diff --git a/tests/testthat/fixtures/expected-pipeline.csv b/tests/testthat/fixtures/expected-pipeline.csv new file mode 100644 index 0000000..303d9bd --- /dev/null +++ b/tests/testthat/fixtures/expected-pipeline.csv @@ -0,0 +1,9 @@ +"SE","cidade","CID10","casos","tcasesmed","inc","Rt","lwr","upr","p1","level" +202052,3304557,"A90",0,0,0,NA,NA,NA,NA,1 +202053,3304557,"A90",1,1,10,NA,NA,NA,NA,1 +202101,3304557,"A90",2,2,20,NA,NA,NA,NA,1 +202102,3304557,"A90",5,5,50,NA,NA,NA,NA,2 +202103,3304557,"A90",12,12,120,NA,NA,NA,NA,2 +202104,3304557,"A90",15,15,150,2.40147661629689,0.849998717753787,4.3952302547316,0.975521154691778,4 +202105,3304557,"A90",4,4,40,0.401804120483044,0.15445950768586,1.15456796595291,0.0471203879655246,4 +202106,3304557,"A90",1,1,10,0.0981488236308544,0.0446554312853891,0.667905536873481,0.000856885984525269,1 diff --git a/tests/testthat/test-core-pipeline.R b/tests/testthat/test-core-pipeline.R index ef24404..451a92c 100644 --- a/tests/testthat/test-core-pipeline.R +++ b/tests/testthat/test-core-pipeline.R @@ -3,6 +3,7 @@ test_that("pure pipeline runs deterministically from in-memory fixtures", { cases <- read_fixture("cases.csv") climate <- read_fixture("climate.csv") parameters <- read_fixture("parameters.csv", stringsAsFactors = FALSE) + expected <- read_fixture("expected-pipeline.csv", stringsAsFactors = FALSE) before <- list.files(all.files = TRUE) first <- alerttools_pipeline( @@ -20,6 +21,10 @@ test_that("pure pipeline runs deterministically from in-memory fixtures", { expect_equal(list.files(all.files = TRUE), before) expect_equal(nrow(first$data), nrow(cases)) expect_equal(nrow(first$alerts), nrow(cases)) + observed <- first$data[c("SE", "cidade", "CID10", "casos", "tcasesmed", + "inc", "Rt", "lwr", "upr", "p1")] + observed$level <- first$alerts$level + expect_equal(observed, expected, tolerance = 1e-6) expect_equal(first$metadata$workers, 1L) expect_true(first$metadata$deterministic) expect_equal(first$diagnostics$missing_climate, 0)