# Create model with 2 unit tests
sfm <- stockflow("SIR") |>
unit_test(expr = all(susceptible >= 0)) |>
# Add test with conditions
unit_test(
label = "lower infection rate",
expr = all(susceptible >= 0),
conditions = list(infection_rate = 0.1)
)
res <- verify(sfm)
# Test results (default)
as.data.frame(res)
# Simulation time-series (long format)
as.data.frame(res, which = "sims") |> head()
# Simulation time-series (wide format)
as.data.frame(res, which = "sims", direction = "wide") |> head()
# Filter to simulation for test 2 only
as.data.frame(res, which = "sims", test = 2) |> head()
# Only simulations for passing tests
as.data.frame(res, which = "sims", status = "pass") |> head()
Run the code above in your browser using DataLab