abstract datatype: domain(T)
Domain of values of type T.
abstract datatype: pick_fun(T)
Picks members of the domain(T)
.
Return pair of {domain(T),T}
; the "output domain" is what will
be used for shrinking the value.
abstract datatype: shrink_fun(T)
Shrinks members of the domain(T)
.
Return pair of {domain(T),T}
; the "output domain" is what will
be used for further shrinking the value.
any/0 | |
atom/0 | |
atom/1 | |
binary/0 | |
binary/1 | |
bool/0 | The domain of booleans. |
char/0 | |
choose/2 | |
domain/3 | Create custom domain. |
elements/1 | Generates a member of the list L . |
eval/1 | Evaluate Body . |
eval/2 | Evaluate Body , replacing occurrences of {call,M,F,A} and {var,N} . |
int/0 | The domain of integers. |
list/1 | Returns the domain of lists of the argument. |
non_empty/1 | |
oneof/1 | |
open/1 | Open a box, yielding a domain which always generates the same value. |
peek/1 | |
pick/2 | The heart of the random structure generator; pick a value from the domain. |
real/0 | The domain of floats. |
resize/2 | |
return/1 | Returns the domain containing exactly Value . |
sample/1 | Generate a sample of output values from a generator. |
sampleshrink/1 | Print a value generated by Domain , followed by a sample of shrinkings. |
seal/1 | Get the domain of boxes of T. |
shrink/2 | The shrinking step function used internally in Triq. |
sized/1 | Support function for the ?SIZED macro. |
tuple/1 | |
vector/2 |
any() -> any()
atom() -> any()
atom(Size) -> any()
binary() -> any()
binary(Size) -> any()
bool() -> domain(true | false)
The domain of booleans. Shrinks to false.
char() -> any()
choose(M, N) -> any()
domain(Name::any(), PickFun::pick_fun(T), ShrinkFun::shrink_fun(T)) -> domain(T)
Create custom domain. This function allows you to create a custom domain with it's own shrinking logic. For instance, the even numbers can be specified thus:
even() -> domain(even, fun(Self,Size) -> Value = (random:uniform(Size) * 2) div 2, {Self, Value} end, fun(Self,Value) when Value>0 -> {Self, Value-2}; (Self,_,0) -> {0, 0} end).
The domain itself (Self
in the above code) is passed as the first argument
to each invocation of both the picking and the shrinking functions.
elements(L::[any()]) -> domain(any())
Generates a member of the list L
. Shrinks towards the first element of the list.
eval(Body::any()) -> any()
Equivalent to eval([], Body).
Evaluate Body
. Occurrences of {call,M,F,A}
is replaced by the result of calling erlang:apply(M,F,A)
, and
occurrences of {var,Name}
in Body
are not substituted.
{call,M,F,A}
are substituted as one would think:
depth first, left-to-right.
eval(PropList::[{atom(), any()}], Body::any()) -> any()
Evaluate Body
, replacing occurrences of {call,M,F,A}
and {var,N}
.
Occurrences of {call,M,F,A}
is replaced by erlang:apply(M,F,A)
, and
{var,Name}
is replaced by the value with key Name
in PropList
.
Exceptions happening when calling erlang:apply/3
are not caught.
If Name
is unbound i.e., Name
does not appear in PropList
or if
Name
is not an atom, {var,Name}
is unchanged.
{call,M,F,A}
are substituted as one would think:
depth first, left-to-right.
int() -> domain(integer())
The domain of integers.
list(ElemDom::domain(T)) -> domain([T])
Returns the domain of lists of the argument.
For example, list(int())
yields the domain of lists of integers.
non_empty(?DOM) -> any()
oneof(DomList) -> any()
Open a box, yielding a domain which always generates the same value.
peek(?BOX) -> any()
pick(Dom::domain(T), SampleSize::pos_integer()) -> {domain(T), T}
The heart of the random structure generator; pick a value from the domain.
Returns a pair of {domain(T), T}
where the first component describes
the structure of the picked value.
real() -> domain(float())
The domain of floats.
resize(Sz, Dom) -> any()
return(Value::Type) -> domain(Type)
Returns the domain containing exactly Value
.
Triq uses internally records of type @
; and so to avoid
interpretation of such values you can wrap it with this. This would
be the case if you have constants in your domains contain the atom @
.
I.e., the following would break because Triq tries to interpret the @
:
?FORALL(X, [int(), {'@', 4}], [IntVal, {'@', 4}] = X )To fix it, do like this:
?FORALL(X, [int(), return({'@', 4})], [IntVal, {'@', 4}] = X )
sample(Dom::domain(T)) -> [T]
Generate a sample of output values from a generator.
sampleshrink(Domain::domain(any())) -> ok
Print a value generated by Domain
, followed by a sample of shrinkings.
For each line of successive output, it prints up to five samples of
shrinking. The first value on each like is used as the target for the next
round of shrinking.
1> sampleshrink(list(int())). [-2,-8,2] [[-1,-8,2],[0,-8,2],[-1,-7,2],[-2,-8,1],[-1,-8,1]] [[0,-8,2],[0,-6,1],[-1,-7,2],[0,-7,2]] [[0,-8,0],[0,-7,0],[0,-7,2],[0,-8,1],[0,-5,2],[0,-7,1]] [[0,-7,0],[0,-5,0]] [[0,-5,0],[0,-6,0]] [[0,-4,0],[0,-3,0]] [[0,-2,0],[0,-3,0],[0,-1,0]] [[0,-1,0]] [[0,0,0]] [[0,0]] [[0]] [[]] ok
Get the domain of boxes of T
The shrinking step function used internally in Triq.
Performs one single step of shrinking. If unsuccessful, i.e. value cound not be shrunk, the output is equal to the input.
Takes aDomain
and a Value
from said domain, and shrinks
the value within the constraints of the domain. The result is
a tuple of a (possibly smaller) output domain, and the
shrunken value.
sized(Fun::'fun'((integer()) -> domain(T))) -> domain(T)
Support function for the ?SIZED macro.
tuple(ElemDom::domain(ElemType::any())) -> domain(tuple(ElemType))
vector(Size, ElemDom) -> any()
Generated by EDoc, May 28 2010, 00:40:18.