[Haskell-cafe] quickCheck problem
Bryan Richter
b at chreekat.net
Wed Oct 7 16:15:58 UTC 2015
On Tue, Oct 06, 2015 at 10:24:03PM +0200, Roelof Wobben wrote:
> Hello,
>
> I have written a function to test if three numbers are the same.
>
> Now I want to test my functions by using quickCheck.
>
> So I thought to test first if all three are the same.
>
> but how can I tell quickcheck that all numbers are the same.
Easy, just generate a single number. :) Make it correct by
construction.
prop_allSame x =
yourFunc x x x == True
> and second question : hwo do the test likeif two numbers are the same.
Now the hard part is not generating two numbers that are the same, but
generating two *different* numbers. To do that you may need to create
a custom generator.
unequalPair = do
x <- arbitrary
y <- arbitrary `suchThat` y /= x
return (x,y)
Now you can use that generator:
prop_twoSame = forAll unequalPair $ \(x,y) ->
yourFunc x x y == False
-- But you might want to test all permutations!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151007/0ba32941/attachment.sig>
More information about the Haskell-Cafe
mailing list