darcs patch: GenT monad transformer variant of Gen (QuickCheck 2)

Felix Martini fmartini at gmail.com
Sun Aug 12 09:06:21 EDT 2007


This patch contains a module GenT for QuickCheck 2. GenT is a monad
transformer variant of the Gen monad.

GenT can be used to test monadic actions with QuickCheck or to create
random values in monads for benchmarking etc.

The module includes two functions to convert GenT actions to and from
Gen. The following is an example that tests some functions in the STM
monad:

prop_InsertLookup :: Gen (STM Bool)
prop_InsertLookup =  toGen $ do
   ht <- lift (new :: STM (HashTable Int String))
   key <- fromGen (arbitrary :: Gen Int)
   value <- fromGen (arbitrary :: Gen String)
   lift $ insert ht key value
   result <- lift $ lookup ht key
   return (result == Just value)

Run the test with: quickCheck $ fmap (unsafePerformIO . atomically)
prop_InsertLookup

Regards,
Felix
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patchset
Type: application/octet-stream
Size: 4540 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/libraries/attachments/20070812/8be0f8ae/patchset-0001.obj


More information about the Libraries mailing list