From f37bc2c5d9ab5dfc716908173f7df397fc732c16 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 6 Jan 2025 15:43:48 +0000 Subject: [PATCH] add plot.multi_epiparameter tests, relates #371 --- .../_snaps/plot/plot-multi-epiparameter.svg | 69 +++++++++++++++++++ tests/testthat/test-plot.R | 25 +++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/testthat/_snaps/plot/plot-multi-epiparameter.svg create mode 100644 tests/testthat/test-plot.R diff --git a/tests/testthat/_snaps/plot/plot-multi-epiparameter.svg b/tests/testthat/_snaps/plot/plot-multi-epiparameter.svg new file mode 100644 index 000000000..9615482d9 --- /dev/null +++ b/tests/testthat/_snaps/plot/plot-multi-epiparameter.svg @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +10 +20 +30 +40 +50 + + + + + + + + +0.00 +0.01 +0.02 +0.03 +0.04 +0.05 +0.06 + +Probability Density Function +Serial Interval (Days) + + + + + + + + diff --git a/tests/testthat/test-plot.R b/tests/testthat/test-plot.R new file mode 100644 index 000000000..cf1146190 --- /dev/null +++ b/tests/testthat/test-plot.R @@ -0,0 +1,25 @@ +test_that("plot.multi_epiparameter works for parameterised ", { + # plotting changes global state of graphics pars so they are restored + op <- par(no.readonly = TRUE) + ep <- epiparameter_db(disease = "Ebola", epi_name = "serial") + expect_silent(plot(ep)) + f <- function() plot(ep) + vdiffr::expect_doppelganger( + title = "plot.multi_epiparameter", + fig = f + ) + # restore graphics pars + par(op) +}) + +test_that("plot.multi_epiparameter removes unparameterised or discrete dists", { + # plotting changes global state of graphics pars so they are restored + op <- par(no.readonly = TRUE) + ep <- epiparameter_db(disease = "SARS") + expect_warning( + plot(ep), + regexp = "(epiparameter)*(discrete or unparameterised)*(cannot be plotted)" + ) + # restore graphics pars + par(op) +}) \ No newline at end of file