forall {hedgehog}R Documentation

Hedgehog property test

Description

Check a property holds for all generated values.

Usage

forall(generator, property, tests = getOption("hedgehog.tests", 100),
  size.limit = getOption("hedgehog.size", 50),
  shrink.limit = getOption("hedgehog.shrinks", 100),
  discard.limit = getOption("hedgehog.discards", 100),
  curry = identical(class(generator), "list"))

Arguments

generator

a generator or list of generators (potentially nested) to use for value testing.

property

a function which takes a value from from the generator and tests some predicated against it.

tests

the number of tests to run

size.limit

the max size used for the generators

shrink.limit

the maximum number of shrinks to run when shrinking a value to find the smallest counterexample.

discard.limit

the maximum number of discards to permit when running the property.

curry

whether to curry the arguments passed to the property, and use do.call to use the list generated as individual arguments. When curry is on, the function arity should be the same as the length of the generated list. Defaults to T if the input is a list.

Details

The generator used can be defined flexibly, in that one can pass in a list of generators, or even nest generators and constant values deeply into the gen argument and the whole construct will be treated as a generator.

Examples

test_that( "Reverse and concatenate symmetry",
  forall( list( as = gen.c( gen.element(1:100) )
              , bs = gen.c( gen.element(1:100) ))
        , function( as, bs )
            expect_identical ( rev(c(as, bs)), c(rev(bs), rev(as)))
  )
)

# False example showing minimum shrink:
## Not run: 
test_that( "Reverse is identity",
  forall ( gen.c( gen.element(1:100)), function(x) { expect_identical ( rev(x), c(x) ) } )
)

## End(Not run)
# Falsifiable after 1 tests, and 5 shrinks
# Predicate is falsifiable

# Counterexample:
# [1] 1 2


[Package hedgehog version 0.1 Index]