Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mdlincoln/fuzzr

Fuzz-Test R Functions
https://github.com/mdlincoln/fuzzr

fuzz-testing r

Last synced: 3 months ago
JSON representation

Fuzz-Test R Functions

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```

# fuzzr

[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/fuzzr)](https://cran.r-project.org/package=fuzzr)
[![Travis-CI Build Status](https://travis-ci.org/mdlincoln/fuzzr.svg?branch=master)](https://travis-ci.org/mdlincoln/fuzzr)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/mdlincoln/fuzzr?branch=master&svg=true)](https://ci.appveyor.com/project/mdlincoln/fuzzr)

fuzzr implements some simple ["fuzz tests"](https://en.wikipedia.org/wiki/Fuzz_testing) for your R functions, passing in a wide array of inputs and returning a report on how your function reacts.

## Installation

```{r, eval = FALSE, purl = FALSE}
install.package("fuzzr")

# Or, for the development version:
devtools::install_github("mdlincoln/fuzzr")
```

## Usage

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.

```{r}
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.

```{r}
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:

```{r}
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:

```{r}
model <- fuzz_value(fuzz_results, subset = "int_multiple")
coefficients(model)
```

### Multiple-argument tests

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.

```{r}
fuzz_p <- p_fuzz_function(agrep, list(pattern = test_char(), x = test_char()))
length(fuzz_p)
knitr::kable(head(as.data.frame(fuzz_p)))
```

---
[Matthew Lincoln](http://matthewlincoln.net)