Learn R Programming

sdbuildR (version 2.0.0)

unit_tests: Display unit tests defined on a stock-and-flow model

Description

Returns an overview of all unit tests attached to the model. The result has a print() method.

Usage

unit_tests(object, test = NULL, label = NULL, ignore_case = TRUE)

Value

An object of class unit_tests_stockflow, printed automatically.

Arguments

object

Stock-and-flow model, object of class stockflow.

test

Integer vector of test number(s) to display (1-based). Defaults to NULL (show all tests). Can be combined with label (intersection).

label

Character vector of regex patterns for partial, case-insensitive label matching. A test is included if its label matches any pattern. E.g., c("non-neg", "beta") returns tests matching either fragment. Can be combined with test (intersection).

ignore_case

Logical; whether label matching is case-insensitive. Default TRUE.

See Also

unit_test(), verify()

Examples

Run this code
sfm <- stockflow("SIR") |>
  unit_test(expr = all(susceptible >= 0)) |>
  unit_test(
    label = "recovered increases over time",
    expr = all(diff(recovered) >= 0)
  )

unit_tests(sfm)
unit_tests(sfm, test = 1L)
unit_tests(sfm, label = "increases")

Run the code above in your browser using DataLab