graham | 12 Nov 20:21 2012

Quickcheck

Hi, 

Trying to find some good docs on QuickCheck, if anyone has one ?

Been scanning what I can find, but a question.

What would be the best way to generate two different/distinct integers ?

Use arbitrary ( if so do you have an example ) or a conditional on the
property.

Though I read the later can reduce passing test count.

Thanks
Graham
Simon Hengel | 12 Nov 22:14 2012
Picon

Re: Quickcheck

On Mon, Nov 12, 2012 at 07:21:06PM +0000, graham <at> fatlazycat.com wrote:
> Hi, 
> 
> Trying to find some good docs on QuickCheck, if anyone has one ?
> 
> Been scanning what I can find, but a question.
> 
> What would be the best way to generate two different/distinct integers ?

I would use Quickcheck's implication operator here:

    quickCheck $ \x y -> x /= (y :: Int) ==> ...

Cheers,
Simon
Iustin Pop | 12 Nov 23:00 2012

Re: Quickcheck

On Mon, Nov 12, 2012 at 10:14:30PM +0100, Simon Hengel wrote:
> On Mon, Nov 12, 2012 at 07:21:06PM +0000, graham <at> fatlazycat.com wrote:
> > Hi, 
> > 
> > Trying to find some good docs on QuickCheck, if anyone has one ?
> > 
> > Been scanning what I can find, but a question.
> > 
> > What would be the best way to generate two different/distinct integers ?
> 
> I would use Quickcheck's implication operator here:
> 
>     quickCheck $ \x y -> x /= (y :: Int) ==> ...

That's good, but it only eliminates test cases after they have been
generated. A slightly better (IMHO) version is to generate "correct"
values in the first place:

    prop_Test :: Property
    prop_Test =
	  forAll (arbitrary::Gen Int) $ \x ->
	  forAll (arbitrary `suchThat` (/= x)) $ \y ->
	  …

regards,
iustin

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
(Continue reading)

graham | 13 Nov 22:52 2012

Re: Quickcheck

Thanks, will try them both. With regards to the implication I assume
it's just regarded as one property test ?

To get two values greater than zero I have something like

prop_something x y = .......do blah with positive integers
  ==> x > 0 && y > 0

But my test fails as it appears to be injecting a negative number and
the test fails. But the implication does not cause the failed test to be
ignored.

Must be missing something ???

Thanks

On Mon, Nov 12, 2012, at 10:00 PM, Iustin Pop wrote:
> On Mon, Nov 12, 2012 at 10:14:30PM +0100, Simon Hengel wrote:
> > On Mon, Nov 12, 2012 at 07:21:06PM +0000, graham <at> fatlazycat.com wrote:
> > > Hi, 
> > > 
> > > Trying to find some good docs on QuickCheck, if anyone has one ?
> > > 
> > > Been scanning what I can find, but a question.
> > > 
> > > What would be the best way to generate two different/distinct integers ?
> > 
> > I would use Quickcheck's implication operator here:
> > 
> >     quickCheck $ \x y -> x /= (y :: Int) ==> ...
(Continue reading)

Clark Gaebel | 13 Nov 22:55 2012
Picon
Picon

Re: Quickcheck

Your implication is backwards. ==> is read "implies"

So your way has "do blah with positive integers" implies "x > 0 && y > 0". That's backwards.

Try prop_something x y = x > 0 && y > 0 ==> ... do blah with positive integers

  - Clark


On Tue, Nov 13, 2012 at 4:52 PM, <graham <at> fatlazycat.com> wrote:
Thanks, will try them both. With regards to the implication I assume
it's just regarded as one property test ?

To get two values greater than zero I have something like

prop_something x y = .......do blah with positive integers
  ==> x > 0 && y > 0

But my test fails as it appears to be injecting a negative number and
the test fails. But the implication does not cause the failed test to be
ignored.

Must be missing something ???

Thanks

On Mon, Nov 12, 2012, at 10:00 PM, Iustin Pop wrote:
> On Mon, Nov 12, 2012 at 10:14:30PM +0100, Simon Hengel wrote:
> > On Mon, Nov 12, 2012 at 07:21:06PM +0000, graham <at> fatlazycat.com wrote:
> > > Hi,
> > >
> > > Trying to find some good docs on QuickCheck, if anyone has one ?
> > >
> > > Been scanning what I can find, but a question.
> > >
> > > What would be the best way to generate two different/distinct integers ?
> >
> > I would use Quickcheck's implication operator here:
> >
> >     quickCheck $ \x y -> x /= (y :: Int) ==> ...
>
> That's good, but it only eliminates test cases after they have been
> generated. A slightly better (IMHO) version is to generate "correct"
> values in the first place:
>
>     prop_Test :: Property
>     prop_Test =
>         forAll (arbitrary::Gen Int) $ \x ->
>         forAll (arbitrary `suchThat` (/= x)) $ \y ->
>         …
>
> regards,
> iustin

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Ozgur Akgun | 13 Nov 22:59 2012
Picon

Re: Quickcheck

hi,

On 13 November 2012 21:52, <graham <at> fatlazycat.com> wrote:
prop_something x y = .......do blah with positive integers
  ==> x > 0 && y > 0

quickcheck provides a few nice new types for such cases. try:

prop_something (Positive x) (Positive y) = ...

this way qc only generates positive numbers, instead of generating and discarding some.

hth,

--
Ozgur Akgun
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
graham | 13 Nov 23:05 2012

Re: Quickcheck

Thanks, that handy and works for my test.
 
Any idea why the implication does not ??? 
 
 
On Tue, Nov 13, 2012, at 09:59 PM, Ozgur Akgun wrote:
hi,
 
On 13 November 2012 21:52, <graham <at> fatlazycat.com> wrote:
prop_something x y = .......do blah with positive integers
  ==> x > 0 && y > 0
 
quickcheck provides a few nice new types for such cases. try:
 
prop_something (Positive x) (Positive y) = ...
 
this way qc only generates positive numbers, instead of generating and discarding some.
 
hth,
 
--
Ozgur Akgun
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane