Module triq_dom

Data Types

domain()

abstract datatype: domain(T)

Domain of values of type T.

pick_fun()

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.

shrink_fun()

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.

Function Index

any/0
atom/0
atom/1
binary/0
binary/1
bool/0The domain of booleans.
char/0
choose/2
domain/3Create custom domain.
elements/1Generates a member of the list L.
eval/1Evaluate Body.
eval/2Evaluate Body, replacing occurrences of {call,M,F,A} and {var,N}.
int/0The domain of integers.
list/1 Returns the domain of lists of the argument.
non_empty/1
oneof/1
open/1Open a box, yielding a domain which always generates the same value.
peek/1
pick/2The heart of the random structure generator; pick a value from the domain.
real/0The domain of floats.
resize/2
return/1Returns the domain containing exactly Value.
sample/1 Generate a sample of output values from a generator.
sampleshrink/1Print a value generated by Domain, followed by a sample of shrinkings.
seal/1Get the domain of boxes of T.
shrink/2The shrinking step function used internally in Triq.
sized/1Support function for the ?SIZED macro.
tuple/1
vector/2

Function Details

any/0

any() -> any()

atom/0

atom() -> any()

atom/1

atom(Size) -> any()

binary/0

binary() -> any()

binary/1

binary(Size) -> any()

bool/0

bool() -> domain(true | false)

The domain of booleans. Shrinks to false.

char/0

char() -> any()

choose/2

choose(M, N) -> any()

domain/3

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.

Both the picking and the shrinking function must return a 2-tuple of the domain of the resulting value, and the value itself.

elements/1

elements(L::[any()]) -> domain(any())

Generates a member of the list L. Shrinks towards the first element of the list.

eval/1

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.

This is a plain function, not a compile_transform or anything like that, so nested functions are not traversed in the substitution. However, nested occurrences of {call,M,F,A} are substituted as one would think: depth first, left-to-right.

eval/2

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.

This is a plain function, not a compile_transform or anything like that, so nested functions are not traversed in the substitution. However, nested occurrences of {call,M,F,A} are substituted as one would think: depth first, left-to-right.

int/0

int() -> domain(integer())

The domain of integers.

list/1

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/1

non_empty(?DOM) -> any()

oneof/1

oneof(DomList) -> any()

open/1

open(?BOX::box(T)) -> domain(T)

Open a box, yielding a domain which always generates the same value.

peek/1

peek(?BOX) -> any()

pick/2

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/0

real() -> domain(float())

The domain of floats.

resize/2

resize(Sz, Dom) -> any()

return/1

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/1

sample(Dom::domain(T)) -> [T]

Generate a sample of output values from a generator.

sampleshrink/1

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

seal/1

seal(Dom::domain(T)) -> domain(box(T))

Get the domain of boxes of T

shrink/2

shrink(Domain::domain(T), Value::T) -> {domain(T), 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 a Domain 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/1

sized(Fun::'fun'((integer()) -> domain(T))) -> domain(T)

Support function for the ?SIZED macro.

tuple/1

tuple(ElemDom::domain(ElemType::any())) -> domain(tuple(ElemType))

vector/2

vector(Size, ElemDom) -> any()


Generated by EDoc, May 28 2010, 00:40:18.