
I have some functions with preconditions. For example, foo::[a]->IO Bool requires a list of at least three elements, and bar::[a]->Int->IO () requires that its second argument is some position within the list. How can I test these with quickcheck? If I use ==>, quickcheck gives up with very few test cases.

On Wednesday 25 May 2011 12:40:20, Guy wrote:
I have some functions with preconditions. For example, foo::[a]->IO Bool requires a list of at least three elements, and bar::[a]->Int->IO () requires that its second argument is some position within the list.
How can I test these with quickcheck? If I use ==>, quickcheck gives up with very few test cases.
You could increase the maxDiscard value, ghci> quickCheckWith stdArgs{ maxDiscard = 5000 } (forAll arbitrary (\xs -> (length xs > 2) ==> whatever)) or create a generator that produces only output fulfilling the preconditions: atLeast3 :: Arbitrary a => Gen [a] atLeast3 = do x <- arbitrary y <- arbitrary z <- arbitrary ws <- arbitrary return (x:y:z:ws) ghci> quickCheck (forAll atLeast3 whatever)

You can write your own generators and use the forall function. Or for these
simple examples you can just test on wrappers:
testFoo :: (a,a,a,[a]) -> IO Bool
testFoo (a1,a2,a3,as) = foo (a1:a2:a3:as)
testBar :: (a,[a]) -> Int -> IO ()
testBar (x,xs) n = bar xs' (n `mod` length xs') where xs' = x:xs
/J
On 25 May 2011 12:40, Guy
I have some functions with preconditions. For example, foo::[a]->IO Bool requires a list of at least three elements, and bar::[a]->Int->IO () requires that its second argument is some position within the list.
How can I test these with quickcheck? If I use ==>, quickcheck gives up with very few test cases.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Thanks, mod is a neat trick for applying the size. Is there a simple way of specifying bounds for quickcheck, or would I have to write a custom generator to do that?
________________________________ From: Jonas Almström Duregård
Sent: Wednesday, 25 May 2011, 14:09 Subject: Re: [Haskell-beginners] Quickcheck Preconditions You can write your own generators and use the forall function. Or for these simple examples you can just test on wrappers:
testFoo :: (a,a,a,[a]) -> IO Bool testFoo (a1,a2,a3,as) = foo (a1:a2:a3:as)
testBar :: (a,[a]) -> Int -> IO () testBar (x,xs) n = bar xs' (n `mod` length xs') where xs' = x:xs
/J

Not sure what you mean by "specifying bounds for quickcheck".
2011/5/25 Guy
Thanks, mod is a neat trick for applying the size. Is there a simple way of specifying bounds for quickcheck, or would I have to write a custom generator to do that?
________________________________ From: Jonas Almström Duregård
Sent: Wednesday, 25 May 2011, 14:09 Subject: Re: [Haskell-beginners] Quickcheck Preconditions You can write your own generators and use the forall function. Or for these simple examples you can just test on wrappers:
testFoo :: (a,a,a,[a]) -> IO Bool testFoo (a1,a2,a3,as) = foo (a1:a2:a3:as)
testBar :: (a,[a]) -> Int -> IO () testBar (x,xs) n = bar xs' (n `mod` length xs') where xs' = x:xs
/J

Simply stating that I need an integer between X and Y On 25/05/2011 18:42, Jonas Almström Duregård wrote:
Not sure what you mean by "specifying bounds for quickcheck".
2011/5/25 Guy
: Thanks, mod is a neat trick for applying the size. Is there a simple way of specifying bounds for quickcheck, or would I have to write a custom generator to do that?
________________________________ From: Jonas Almström Duregård
Sent: Wednesday, 25 May 2011, 14:09 Subject: Re: [Haskell-beginners] Quickcheck Preconditions You can write your own generators and use the forall function. Or for these simple examples you can just test on wrappers:
testFoo :: (a,a,a,[a]) -> IO Bool testFoo (a1,a2,a3,as) = foo (a1:a2:a3:as)
testBar :: (a,[a]) -> Int -> IO () testBar (x,xs) n = bar xs' (n `mod` length xs') where xs' = x:xs
/J

abs $ (n `mod` (y - x)) + x
Provided y > x >= 0.
/J
On 25 May 2011 18:13, Guy
Simply stating that I need an integer between X and Y
On 25/05/2011 18:42, Jonas Almström Duregård wrote:
Not sure what you mean by "specifying bounds for quickcheck".
2011/5/25 Guy
: Thanks, mod is a neat trick for applying the size. Is there a simple way of specifying bounds for quickcheck, or would I have to write a custom generator to do that?
________________________________
From: Jonas Almström Duregård
Sent: Wednesday, 25 May 2011, 14:09 Subject: Re: [Haskell-beginners] Quickcheck Preconditions You can write your own generators and use the forall function. Or for these simple examples you can just test on wrappers:
testFoo :: (a,a,a,[a]) -> IO Bool testFoo (a1,a2,a3,as) = foo (a1:a2:a3:as)
testBar :: (a,[a]) -> Int -> IO () testBar (x,xs) n = bar xs' (n `mod` length xs') where xs' = x:xs
/J
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (3)
-
Daniel Fischer
-
Guy
-
Jonas Almström Duregård