How to get a sample of a generator?

只愿长相守 提交于 2020-01-06 03:26:09

问题


I'm using Triq 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("triq/include/triq.hrl").
-export([valid_type_gen/1]).

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

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

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

回答1:


Ok, I figured it out, I just need to call the sample function:

1> hd(triq_dom:sample(my:valid_type_gen())).
[8,4,3,7,6,8,11,7,5,7]

That will generate a bunch of samples, and I take the first one.



来源:https://stackoverflow.com/questions/36440822/how-to-get-a-sample-of-a-generator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!