如何获取发电机的样品? [英] How to get a sample of a generator?

查看:184
本文介绍了如何获取发电机的样品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Triq 编写我的基于属性的测试。
如何查看我的生成器生成的数据类型?

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

假设我有以下生成器:

-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"]


推荐答案

好的,我想出来,我只需要调用示例功能:

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.

这篇关于如何获取发电机的样品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆