Generating a lists of a specific length with Haskell's QuickCheck -
-- 3 (find k"th element of 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 prop_3a ran through quickcheck, gives up, because won't generate long enough lists.
how can write generator generate lists length longer random integer?
how going other way? first let quickcheck pick list , constrain indices allow. works, , not throw away test cases.
prop_3a (nonempty xs) = forall (choose (0, length xs - 1)) $ \i -> element_at xs == (xs !! :: int)
here, use forall
use specific generator indices, in case using choose
picks element specified range, , use the nonemptylist
type ensure don't try index empty list.
Comments
Post a Comment