27

Okay, as I learned via my previous question, the RWH book is already out of date for QuickCheck. And despite all the posts I've read that tell me how incredibly simple it is to use QuickCheck, I cannot find any place that tells me how to change the number of tests to run for a property.

RWH says:

handyCheck limit = check defaultConfig {
                     configMaxTest = limit
                   , configEvery   = \_ _ -> ""
                   }

How to do this with QuickCheck 2.4? More importantly, how would I have found out myself? Please don't tell me that I should've been able to figure it out from the API documentation.

Community
  • 1
  • 1

2 Answers2

50

You are looking for:

quickCheckWith stdArgs { maxSuccess = 5000 } someProp

How I found out

  1. I went to the API documentation.
  2. The 2nd thing I saw, after quickCheck was the Args type with a maxSuccess field.
  3. I didn't want to write all the fields, so I looked for a value of type Args - finding stdArgs. (Use your browsers search function - ctrl-f usually). OTOH, I could have used hoogle.
  4. I needed to use my Args type somewhere so I kept looking. The next line was quickCheckWith - bingo! On the other hand, I could have used hoogle.

How Else Can You Find Out

As I stated above, you could have used hoogle to find a lot of the functions, assuming you realize the Args type is the core of what you need (from the haddocks).

Otherwise, you are probably reduced to looking at what other packages do, which means you need to know what other packages are worth looking at. The examples folder in QuickCheck seems obvious, but not all packages include such examples. Using reverse dependencies you can often find a package to look at, but for QC lots of packages don't have explicit dependencies.

Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166
  • 6
    Hi Thomas. I can appreciate that you were able to find out via the API. But I'm not yet initiated into this package, and I can't make heads or tails of most of it. Lost on Arbitrary. Way lost on CoArbitrary. Gen? No idea what that is either. The documentation says "random generator". I hope you understand what I mean. But thanks for providing a quick answer. –  Nov 14 '11 at 01:39
  • 4
    @Ana Understandable that you're lost on Arbitrary, CoArbitrary and whatnot. The trick is, don't be too intimidated by such stuff. Most APIs have an easy part that gets you started, so try to ignore the complicated stuff and find the easy part first. In this case, you want to _check_ your code, so search for functions containing 'check' in their name (case insensitive because of camelCase), and see what looks useful. – Daniel Fischer Nov 14 '11 at 04:15
4

For those who want to run all tests at once and provide their configuration:

return []
main = $forAllProperties (quickCheckWithResult stdArgs { maxSuccess = 500 })
Konstantin Milyutin
  • 11,946
  • 11
  • 59
  • 85
  • thank you for this answer - quickcheck is either complicated or lacking in documenation. i did all the finding described above and did stdArgs { maxSize = 500 } which did reduced the number of samples; i did misundestanding the documentation. – user855443 Apr 10 '16 at 07:08