Haskell quickcheck - how to generate only printable strings

后端 未结 2 1690
时光取名叫无心
时光取名叫无心 2021-02-07 01:15

I have a set of simple demo programs which encode/decode strings, and want to generate some quickCheck tests for them, but to limit the tests to printable strings only.

2条回答
  •  礼貌的吻别
    2021-02-07 02:08

    Currently QuickCheck has a PrintableString type, which also has an instance of arbitrary, which means that you can readily generate arbitrary strings with:

    arbitraryPrintableString :: Gen String
    arbitraryPrintableString = getPrintableString <$> arbitrary
    

提交回复
热议问题