Module triq_dom

Data Types

box()

box(T) = #'@box'{dom = domain(T), value = T}

domain()

abstract datatype: domain(T)

Domain of values of type T.

domrec()

domrec(T) = {'@', atom() | tuple(), pick_fun(T), shrink_fun(T), boolean()}

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.

uchar()

abstract datatype: uchar()

Valid unicode code point.

uchars()

uchars() = unicode:unicode_characters()

Function Index

any/0
atom/0The domain of atoms.
atom/1
binary/0
binary/1
bitstring/0The domain of bitstrings.
bitstring/1
bool/0The domain of booleans.
byte/0
char/0
choose/2
domain/3Create custom domain.
elements/1Generates a member of the list L.
float/0
frequency/1Choose domain from list [{Weight, Domain}, ...].
int/0The domain of integers.
int/1
int/2
largeint/0The domain of "big" integers.
list/1 Returns the domain of lists of the argument.
non_empty/1
non_neg_integer/0The domain of non-negative integers.
noshrink/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.
pos_integer/0The domain of positive integers.
real/0The domain of floats.
resize/2
return/1Returns the domain containing exactly Value.
sample/1Generate 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.
shrink_without_duplicates/1
sized/1Support function for the ?SIZED macro.
tuple/1
unicode_binary/0
unicode_binary/1Generate an unicode binary binary.
unicode_binary/2Generate an unicode binary.
unicode_char/0
unicode_characters/0
unicode_characters/1
unicode_string/0Generate a list of unicode code points.
unicode_string/1Generate a list of unicode code points of length Size.
vector/2

Function Details

any/0

any() -> domain(any())

atom/0

atom() -> domain(integer())

The domain of atoms

atom/1

atom(Size::non_neg_integer()) -> domrec(atom())

binary/0

binary() -> domrec(binary())

binary/1

binary(Size::non_neg_integer()) -> domrec(binary())

bitstring/0

bitstring() -> domain(bitstring())

The domain of bitstrings

bitstring/1

bitstring(Size::non_neg_integer()) -> domrec(bitstring())

bool/0

bool() -> domain(true | false)

The domain of booleans. Shrinks to false.

byte/0

byte() -> domrec(integer())

char/0

char() -> domrec(32..126)

choose/2

choose(M::integer(), N::integer()) -> domrec(integer())

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 = (triq_rnd: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.

float/0

float() -> domrec(float())

frequency/1

frequency(GenList) -> any()

Choose domain from list [{Weight, Domain}, ...]

int/0

int() -> domain(integer())

The domain of integers.

int/1

int(Max) -> any()

int/2

int(Min, Max) -> any()

largeint/0

largeint() -> domrec(largeint())

The domain of "big" integers.

Note, this is sized to ensure it remains a big integer, even on 64 bit implementations.

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()

non_neg_integer/0

non_neg_integer() -> domain(non_neg_integer())

The domain of non-negative integers.

noshrink/1

noshrink(Dom::domain(T)) -> domain(T)

oneof/1

oneof(DomList::[domain(T)]) -> domain(T)

open/1

open(Box::box(T)) -> domain(T)

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

peek/1

peek(X1::box(T)) -> T

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.

pos_integer/0

pos_integer() -> domain(pos_integer())

The domain of positive integers.

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. This should not be used except for REPL testing purposes; it will only ever generate fairly small-valued samples.

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.

shrink_without_duplicates/1

shrink_without_duplicates(Dom) -> any()

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))

unicode_binary/0

unicode_binary() -> domrec(binary())

unicode_binary/1

unicode_binary(Size::Size | Encoding) -> domrec(binary())

Generate an unicode binary binary.

unicode_binary/2

unicode_binary(Size, Encoding) -> domrec(binary())

Generate an unicode binary.

unicode_char/0

unicode_char() -> domrec(uchar())

unicode_characters/0

unicode_characters() -> domrec(uchars())

unicode_characters/1

unicode_characters(Encoding) -> domrec(uchars())

unicode_string/0

unicode_string() -> domrec([uchar()])

Generate a list of unicode code points.

unicode_string/1

unicode_string(Size::non_neg_integer()) -> domrec([uchar()])

Generate a list of unicode code points of length Size.

vector/2

vector(Size, ElemDom) -> any()


Generated by EDoc