如何将QuickCheck参数限制为非空字符串列表? [英] How can I constrain a QuickCheck parameter to a list of non-empty Strings?

查看:60
本文介绍了如何将QuickCheck参数限制为非空字符串列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含字符串列表的属性:

I have a property that takes a list of Strings:

myProp :: [String]->布尔

我需要限制QuickCheck生成的输入,以便列表中仅包含非空字符串.

I need to constrain the inputs that QuickCheck generates so that only non-empty strings are in the list.

我该怎么做?

推荐答案

您使用

You use forAll together with listOf (which generates lists) and listOf1 (which generates non-empty lists).

quickCheck $ forAll (listOf $ listOf1 arbitrary) $ myProp

-- more verbose alternative to make things clear
nonEmptyString :: Gen String
nonEmptyString = listOf1 arbitrary

quickCheck $ forAll (listOf nonEmptyString) $ myProp

这篇关于如何将QuickCheck参数限制为非空字符串列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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