
Thanks, but why this part : x (x + y) (x - (y + 1)) Roelof Op 6-10-2015 om 22:31 schreef Rogan Creswick:
On Tue, Oct 6, 2015 at 1:24 PM, 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. Just have quickcheck generate one number, and use it for all three arguments, eg:
prop_allSame :: Int -> Bool prop_allSame x = yourFn x x x
then test the other cases:
prop_different :: Int -> Int -> Int -> Property prop_different x y z = x /= y && y /= z && x /= z ==> not $ yourFn x y z
That's probably OK for ints, but generally the guard in that style isn't a great solution, since quickcheck will just keep generating inputs until the predicate is satisfied. That can take a while, so you could also manually offset the first input in various ways:
prop_different :: Int -> Int -> Bool prop_different x y = not $ yourFn x (x + y) (x - (y + 1)) -- I put a +1 in here to avoid returning true where y = 0,
There are probably other ways to mutate a randomly generated input for your problem that may work better, but that's the general idea.
--Rogan
and second question : hwo do the test likeif two numbers are the same.
I ask this because I try to solve a exercise of the programming Haskell book, IM have read chapter 3 now.
Roelof
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
----- Geen virus gevonden in dit bericht. Gecontroleerd door AVG - www.avg.com Versie: 2015.0.6140 / Virusdatabase: 4435/10768 - datum van uitgifte: 10/06/15