In Erlang's PropEr, how to get a sample of a generator?

284 views Asked by At

I'm using PropEr to write my property based test. How can I see what kind of data my generator produces?

Let's say I have the following generator:

-module(my).
-include_lib("proper/include/proper.hrl").
-export([valid_type_gen/0]).

valid_type_gen() -> non_empty(list(any())).

I would like to examine what kind of data it generates, i.e. something like:

$ erl
1> my:valid_type_gen().sample() %???
[1,b,"blah"]

For the same question in Triq, look here.

1

There are 1 answers

0
aronisstav On BEST ANSWER

The relevant function is proper_gen:pick/1. It returns a tuple {ok, V}.

$ erl
1> proper_gen:pick(my:valid_type_gen()).
{ok,[{{},<<>>,2},
     [{},11.690292064109402,
      {{}},
      {},18.096053885231132,u,')[\2064Wue¢±'],
     [{},-5.041761022794527,-13,
      {[],-0.9553811124968509},
      -5,'õ\232zc}:Ì'],
     <<47,5,113,69,86,216,20,142,173,57:6>>,
     '',
     {2.710196163900066,0.47155396154628,{},[],
      {[]},
      8.42398680461108},
     {[[25,
        [-10.073999184421432,5.734631070941083,
         {'æ\2367Ò§ü\233"',[30.925337851024143]}]],
       '']},
     '\031Þ\037\'\v','\214b\236']}