[Haskell-cafe] Need advise with using Quickcheck

Han Joosten han.joosten.han at gmail.com
Sat Jun 12 10:49:47 UTC 2021


Thanks for this respons, Rubén. I might not have explained what I am
looking for very well.
I already have
instance Arbitrary Foo
That is not the problem. The problem is, that when a counterexample is
found, it is dumped to the output with the `show` function. I would like to
be able to use another function for that, say show'. In order to do so, I
need to obtain the counterexample itself in some way, so I can use it to
generate a useful message after the tests are done.

Op vr 11 jun. 2021 om 23:31 schreef Ruben Astudillo <ruben.astud at gmail.com>:

> Hello Han
>
> On 11-06-21 17:16, Han Joosten wrote:
> > [..]
> > *parseFoo :: Text -> Guarded Foo*
> > *prettyFoo :: Foo -> Text*
> >
> > The idea is that for all foo :: Foo, the following holds:
> >     *parseFoo . prettyFoo $ foo*  should be equal to  *Checked foo []*
> >
> > Now, if there is a counterexample, I would like to see prettyFoo foo as
> > output, folowed by the show of the Errors part.
>
> It seems you know what property should hold for `parseFoo` and `prettyFoo`.
> Per the QuickCheck manual [1] this could be written as
>
>     import Test.QuickCheck
>
>     propOnAllFooText :: Property
>     propOnAllFooText = forAll (arbitrary :: Gen Foo) $ \exFoo ->
>         parseFoo (prettyFoo exFoo) == Checked exFoo []
>
> What you are missing is a way to generate the test cases (the `arbitrary'
> generator above). You need a way to declare this instance
>
>     instance Arbitrary Foo where
>         -- arbitrary :: Gen Foo
>         arbitrary = <something>
>
> You can see example on how to define it on the manual [1]. Good luck.
>
> [1]: http://www.cse.chalmers.se/~rjmh/QuickCheck/manual.html
>
> --
> -- Rubén
> -- pgp: 4EE9 28F7 932E F4AD
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210612/dcc0818c/attachment.html>


More information about the Haskell-Cafe mailing list