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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With