How can I limit the QuickCheck parameter to a list of non-empty lines?

I have a property that takes a list of strings:

myProp :: [String] -> Bool

I need to limit the inputs generated by QuickCheck so that only non-empty lines are listed.

How can i do this?

+4
source share
3 answers

You use forAlltogether 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
+4
source
import Test.QuickCheck.Modifiers (NonEmptyList (..))

myProp :: [NonEmptyList Char] -> Bool
myProp xs0 =
  let xs = map getNonEmpty xs0
  in ...
+3
source

, ( ):

quickCheck $ \ h t -> let {s :: String ; s = h : t } in length s > 0

s .

+2

All Articles