Skip to content

Test suite: testthat edition 3, numerical validation, coverage 80% to 93% (#215) - #246

Merged
feralaes merged 2 commits into
mainfrom
215-tests-edition3
Nov 13, 2026
Merged

feralaes merged 2 commits into
mainfrom
215-tests-edition3

Conversation

@feralaes

Copy link
Copy Markdown
Collaborator

Closes #215

testthat edition 3 (commit 1)

  • Config/testthat/edition: 3 in DESCRIPTION.
  • Removed the 18 context() calls and converted the 41 expect_is() calls to expect_s3_class(). Both are deprecated in edition 3.
  • util_models_detfun.R → helper-models.R, which testthat loads automatically, so it no longer needs to be source()d.
  • test_elc.R: check.names (an all.equal() argument) becomes ignore_attr. Its reference calculation now breaks max.col() ties with "first", as the package does since CEAC max.col returns random indices #167.

All 263 existing expectations pass with no warnings.

Numerical validation (commit 2)

  • Method-of-moments helpers reproduce the requested mean and spread exactly: beta_params(), gamma_params() (scale and rate forms), lnorm_params(), and dirichlet_params().
  • gen_psa_samp(): every distribution and parameterization gives samples with the expected moments (n = 20,000, fixed seed):
    • normal; log-normal (mean/sd and meanlog/sdlog); truncated normal (stays within its bounds); beta (mean/sd and a/b); gamma (mean/sd and shape/scale);
    • Dirichlet (value/mean_prop/sd, value/n, value/alpha; rows sum to 1); bootstrap (weighted mean); triangle; constant.
  • Together with Convert between BCEA and dampack objects: bcea_to_psa() and psa_to_bcea() (#204) #244, where calc_evpi() matches BCEA's EVPI to within 1e-8, this gives external checks of the core calculations for the JOSS paper.

Branch coverage

Each new test checks what an option changes, not just that the code runs:

  • Plots (test_plot_options.R):
    • plot.psa() with center, ellipse, color, reference axes and caption options;
    • plot.ceac() with frontier, points and min_prob (strategies below the threshold are dropped);
    • the three plot.evsi() layouts, by sample size, WTP, or both;
    • plot.evppi();
    • owsa_tornado()'s returned data, relative-difference filter and two-strategy comparison.
  • Metamodels: summary.metamodel() (one-way lm and GAM, two-way, and the multiway error) and print.metamodel().
  • run_psa(): params_basecase, strategy names taken from FUN, checks on FUN's output, and progress output.

Coverage (covr)

79.97% → 93.08%. The lowest file is now dsa_twoway.R at 77.8%; all others are at 85% or more. Codecov will confirm the number on this PR.

Verification

  • 338 expectations pass, 0 lints.
  • Outputs of every vignette and help-page example are identical to main. Only test files and DESCRIPTION change.
  • R CMD check --as-cran: 0 errors, 0 warnings, 1 NOTE (the development version number).

Not included

  • vdiffr image snapshots: optional, and fragile across ggplot2 versions.
  • ICERs against the published Hunink et al. (2014) values for hund_strat: I don't have the reference table. If someone shares it, it's a short test to add.

- Config/testthat/edition: 3 in DESCRIPTION.
- Remove the 18 context() calls and convert the 41 expect_is() calls to
  expect_s3_class(); both are deprecated in edition 3.
- Rename tests/testthat/util_models_detfun.R to helper-models.R, which
  testthat loads automatically, instead of source()-ing it.
- test_elc.R: check.names (an all.equal() argument) becomes ignore_attr,
  and the reference calculation breaks max.col() ties with 'first', as
  the package does since #167.

All 263 expectations pass with no warnings.
Numerical validation:
- beta_params(), gamma_params() (scale and rate), lnorm_params(), and
  dirichlet_params() reproduce the requested mean and spread exactly.
- gen_psa_samp(): every distribution and parameterization (normal, both
  log-normal forms, truncated normal, both beta and gamma forms, all
  three Dirichlet forms, bootstrap, triangle, constant) gives samples
  with the expected moments (n = 20,000, fixed seed).

Branch coverage (each test checks what the option changes):
- test_plot_options.R: plot.psa() center/ellipse/col/ref options,
  plot.ceac() frontier/points/min_prob, the three plot.evsi() layouts,
  plot.evppi(), owsa_tornado() data/filter/two-strategy comparison.
- summary.metamodel() (one-way lm and gam, two-way, multiway error) and
  print.metamodel().
- run_psa(): params_basecase, strategies taken from FUN, FUN output
  checks, progress output.

Coverage (covr): 79.97% -> 93.08%.
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.08%. Comparing base (8a9bea9) to head (64e8714).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #246       +/-   ##
===========================================
+ Coverage   79.96%   93.08%   +13.11%     
===========================================
  Files          18       18               
  Lines        1822     1822               
===========================================
+ Hits         1457     1696      +239     
+ Misses        365      126      -239     

see 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@feralaes
feralaes merged commit 755c612 into main Nov 13, 2026
11 checks passed
@feralaes
feralaes deleted the 215-tests-edition3 branch November 13, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test suite upgrade: testthat edition 3, coverage ≥ 80%, numerical validation

1 participant