[Haskell-cafe] quickCheck problem

Rogan Creswick creswick at gmail.com
Wed Oct 7 16:32:02 UTC 2015


On Wed, Oct 7, 2015 at 12:13 AM, Roelof Wobben <r.wobben at home.nl> wrote:
> I know that if three numbers are the same then the outcome will be false.
> The same if two numbers are the same.
>
> Can I not do something like this :
>
> prop_different x y z = not( (x /= y && y /= z && x /= z))
>
> to test all cases at once.

That looks like it will work (I'm assuming you're actually calling
your function in the property and comparing with that boolean
expression); is that the same way your function is implemented?

--Rogan

>
> Roelof
>
>
>
> Op 7-10-2015 om 00:28 schreef Rogan Creswick:
>
>> On Tue, Oct 6, 2015 at 2:01 PM, Roelof Wobben <r.wobben at home.nl> wrote:
>>>
>>> but why this part :
>>>
>>> x (x + y) (x - (y + 1))
>>
>> That is buggy.  I was trying to quickly create three arguments that
>> are guaranteed to be different by some random amount, but what I wrote
>> doesn't always work (eg: if y = 0, then the first two arguments are
>> the same, if y is -1, the first and 3rd are the same, if x is MAX_INT,
>> then it may or may not be the same as other arguments, depending on Y,
>> etc...)
>>
>> The predicate guard should work, though it may take longer to run.
>>
>> --Rogan
>>
>>>
>>> Roelof
>>>
>>> Op 6-10-2015 om 22:31 schreef Rogan Creswick:
>>>>
>>>> On Tue, Oct 6, 2015 at 1:24 PM, Roelof Wobben <r.wobben at home.nl> 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 at 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
>>>>
>>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe at 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
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list