Description Usage Arguments Details Examples
Check a property holds for all generated values.
1 2 3 4 5 |
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 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.