knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
fuzzr implements some simple "fuzz tests" for your R functions, passing in a wide array of inputs and returning a report on how your function reacts.
install.package("fuzzr") # Or, for the development version: devtools::install_github("mdlincoln/fuzzr")
Tests are set by passing functions that return named lists of input values.
These values will be passed as function arguments.
Several default suites are provided with this package, such as test_char
, however you may implement your own by passing a function that returns a similarly-formatted list.
library(fuzzr) str(test_char())
Evaluate a function argument by supplying fuzz_function
its quoted name, the tests to run, along with any other required static values.
fuzz_function
returns a fuzz_results
object that stores conditions raised by a function (message, warning, or error) along with any value returned by that function.
fuzz_results <- fuzz_function(fun = lm, arg_name = "subset", data = iris, formula = Sepal.Length ~ Petal.Width + Petal.Length, tests = test_all())
You can render these results as a data frame:
fuzz_df <- as.data.frame(fuzz_results) knitr::kable(head(fuzz_df))
You can also access the value returned by any one test by matching the argument tested with its test name:
model <- fuzz_value(fuzz_results, subset = "int_multiple") coefficients(model)
Specify multiple-argument tests with p_fuzz_function
, passing a named list of arguments and tests to run on each.
p_fuzz_function
will test every combination of argument and variable.
fuzz_p <- p_fuzz_function(agrep, list(pattern = test_char(), x = test_char())) length(fuzz_p) knitr::kable(head(as.data.frame(fuzz_p)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.