Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set constant seeds for Haskell's quickCheck function

Every time I run "quickCheck prop_xyz", a new random seed is used. How do I enforce QuickCheck to always use the same random seed?

Thanks!

like image 271
user1546806 Avatar asked Jan 12 '23 05:01

user1546806


1 Answers

The functionality you need is in Test.QuickCheck; use quickCheckWith to specify custom Args. In particular, there's the replay :: Maybe (StdGen, Int) field, which allows you to replay tests. So you can use the stdArgs defaults and tweak them; for instance,

ghci> :load Main.hs
ghci> import Test.QuickCheck
ghci> import System.Random -- for mkStdGen
ghci> quickCheckWith stdArgs{replay = Just (mkStdGen 42, 0)} prop_xyz

The second component of the tuple has to do with the size of the test cases, but I forget exactly what.

like image 135
Antal Spector-Zabusky Avatar answered Jan 17 '23 16:01

Antal Spector-Zabusky