quickCheck generation question

I'm going through the 99 Haskell problems and am trying to write quickCheck properties for each one. -- 3 (find k"th element of a list) element_at xs x = xs !! x prop_3a xs x = (x < length xs && x >= 0) ==> element_at xs (x::Int) == (xs !! x::Int) When I run prop_3a through quickCheck, it gives up, saying that it only passed 1 test. This makes sense, because the random x is going to be larger than the number of elements in the random list in most cases. So what I need to do is write a generator that generates a random list with length larger than a random integer, but I'm not sure how to do that. Thanks! Joe

Solved this: http://stackoverflow.com/questions/7693930/generating-a-lists-of-a-specific-...
On Fri, Oct 7, 2011 at 4:40 PM, Joe Van Dyk
I'm going through the 99 Haskell problems and am trying to write quickCheck properties for each one.
-- 3 (find k"th element of a list) element_at xs x = xs !! x prop_3a xs x = (x < length xs && x >= 0) ==> element_at xs (x::Int) == (xs !! x::Int)
When I run prop_3a through quickCheck, it gives up, saying that it only passed 1 test. This makes sense, because the random x is going to be larger than the number of elements in the random list in most cases.
So what I need to do is write a generator that generates a random list with length larger than a random integer, but I'm not sure how to do that.
Thanks! Joe

Am 08.10.2011 01:40, schrieb Joe Van Dyk:
I'm going through the 99 Haskell problems and am trying to write quickCheck properties for each one.
-- 3 (find k"th element of a list) element_at xs x = xs !! x prop_3a xs x = (x< length xs&& x>= 0) ==> element_at xs (x::Int) == (xs !! x::Int)
The definition and test look very similar (basically "=" is replaced by "=="). So this seems to test reliability of definitions and Eq instances. Such tests should not be necessary. (Testing different implementations for equality makes more sense.) Cheers Christian

On Mon, Oct 10, 2011 at 6:26 AM, Christian Maeder
Am 08.10.2011 01:40, schrieb Joe Van Dyk:
I'm going through the 99 Haskell problems and am trying to write quickCheck properties for each one.
-- 3 (find k"th element of a list) element_at xs x = xs !! x prop_3a xs x = (x< length xs&& x>= 0) ==> element_at xs (x::Int) == (xs !! x::Int)
The definition and test look very similar (basically "=" is replaced by "=="). So this seems to test reliability of definitions and Eq instances. Such tests should not be necessary. (Testing different implementations for equality makes more sense.)
Well, yes, of course. The point is learning how the tests work, not the code under test. Joe
participants (2)
-
Christian Maeder
-
Joe Van Dyk