Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I constrain a QuickCheck parameter to a list of non-empty Strings?

I have a property that takes a list of Strings:

myProp :: [String] -> Bool

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

How can I do this?

like image 214
Colin McEnearney Avatar asked Feb 04 '15 19:02

Colin McEnearney


1 Answers

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

Examples

quickCheck $ forAll (listOf $ listOf1 arbitrary) $ myProp
-- more verbose alternative to make things clear
nonEmptyString :: Gen String
nonEmptyString = listOf1 arbitrary

quickCheck $ forAll (listOf nonEmptyString) $ myProp
like image 60
Zeta Avatar answered Sep 28 '22 13:09

Zeta