Run all active unit tests defined on a stock-and-flow model. Use
unit_test() to define tests; use unit_tests() to display them.
Usage
# S3 method for class 'stockflow'
verify(object, test = NULL, ...)Arguments
- object
An
stockflowobject.- test
Integer vector of test number(s) to run (numbers-based, as shown by
unit_tests()). Defaults toNULL(run all tests).- ...
Additional arguments passed to
sim_settings()(e.g.,seed,dt).
Value
An object of class verify_stockflow, returned invisibly. Use
as.data.frame() to extract results as a data frame and plot() to
visualize the simulations used. The object contains:
- results
List of test result entries, one per test (including inactive tests, which appear with
status = "skip"). Each entry haslabel,expr_str,conditions,status,error_type,message, andoutcome.- object
The
stockflowmodel the tests were run against.- sims
Nested list of
simulate_stockflowobjects used internally byplot.verify_stockflow(). Always present (neverNULL).- j
Named integer vector mapping each test label to its condition index. Used internally by
plot.verify_stockflow().- n
Number of simulations run per condition.
- n_conditions
Number of unique simulation conditions.
- test_indices
Integer vector of the original 1-based test numbers that were run (as shown by
unit_tests()). Equal toseq_along(results)whentest = NULL(all tests run).
Details
Calling verify() on a stockflow model will first simulate the model, then
run all tests — including those that require re-simulation under alternative
conditions. Simulations are always retained in the returned
object so that plot.verify_stockflow() works without any extra arguments.
For repeated-run robustness testing use ensemble() instead.
Examples
sfm <- stockflow("SIR") |>
unit_test(expr = all(susceptible >= 0)) |>
unit_test(
label = "recovered increases over time",
expr = all(diff(recovered) >= 0)
)
verify(sfm)
#>
#> ── Stock-and-Flow Unit Test Results ────────────────────────────────────────────
#> 2/2 tests passed.
#> ✔ 1. susceptible is at least 0 (for all values)
#> ✔ 2. recovered increases over time