[Haskell-beginners] QuickCheck properties on monadic values

Rahul Kapoor rahulk at artquiver.com
Fri May 21 14:27:45 EDT 2010


Ashish

Test.QuickCheck.Monadic should give you the building blocks you need.

For example here is a snippet which turns a value and a function of
type a -> IO a
into a regular property.

import Test.QuickCheck.Monadic (monadicIO, assert, run, pick)
..
..
propIO :: Show a => Gen a -> (a -> IO Bool) -> Property
propIO gen prop = monadicIO $ do
                    v <- pick gen
                    b <- run $ prop v
                    assert b


You can find some examples of madic quick check properties at:
http://github.com/trie/yay/blob/master/tests/Syck.hs


HTH,
Rahul

On Fri, May 21, 2010 at 12:47 PM, Ashish Agarwal <agarwal1975 at gmail.com> wrote:
> I've been using the binary library, and would like to test whether my put
> and get functions are inverses. I thought of using QuickCheck but it is not
> clear how I can write the necessary property. I skimmed Claessen, Hughes,
> "Testing monadic code with QuickCheck", but their examples require a lot of
> extra work (e.g. their queue example requires an AST for a mini-queue
> language). Am I missing something obvious?
> Also, what's the difference between QuickCheck 1 and 2? I'm on gch 6.10 and
> doing `cabal install QuickCheck` gives me version 1.2.0.0, which lacks
> constructs described in the above paper.
> Thanks.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>


More information about the Beginners mailing list