nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
724 stars 121 forks source link

Word does not obey maxSize. #182

Closed kindaro closed 6 years ago

kindaro commented 7 years ago

So I've been toying with prime numbers and, you see, I can't directly find out if a number such as maxBound :: Word is one or not. Not in a lifetime anyway. So I set up a quickCheckWith (stdArgs { maxSize = 1024 }) ... to make sure I live to see the test results. Imagine my shock wnen it occured that the Ints generated fall within the "safe" range but Word figures quickly rise to the order of maxBound, on which I can't expect termination in a reasonable time frame.

λ f x = ioProperty $ print (x :: Word) >> return True
λ quickCheckWith (stdArgs { maxSize = 1024 }) f
10 tests)
111test) 
33100sts)
7281571s)
4148347294
817501862554
226853897592308
13647715807314315
2247646138320600033
16617628839815712773
13457765222048383576
16244950995656755043
11865362732110771918
677049019966763797
6271376520995031147
16993458778071649508
...

Is this intended?


I want to underline that Ints fall very much within the range.

I use stack with more or less the latest nightly snapshot.

nick8325 commented 6 years ago

It's intended but not thought through very carefully.

Int8/16/32/64 and Word8/16/32/64 all generate integers from the full range of their type.

Ideally, I would like Int and Word to also do that. However, Int in Haskell most often represents a small integer, such as the length of a list (or at any rate small integers are usually represented as Int). That's why Int has a different generator, which only generates small values.

I'm not sure that the same reasoning applies to Word, which is why it uses the same generator as Word32/64. However, I may be wrong, and it could also be good for predictability to let Int and Word have the same generator. I will leave this open for now to see if anyone else has an opinion.

kindaro commented 6 years ago

So, does maxSize have any effect on those types whose generators generate integers from their full range?

nick8325 commented 6 years ago

Yes - the full range is only generated when the size is at least 100 (the default maximum size for QuickCheck). Smaller sizes generate smaller integers - you can sort of see this in your output above.

nick8325 commented 6 years ago

Fixed by 0d547a4.