Make Test.QuickCheck.Batch use a default type for testing list functions
Asked Answered
G

1

6

I am testing a function called extractions that operates over any list.

extractions :: [a] -> [(a,[a])]
extractions [] = []
extractions l = extract l []
    where extract [] _ = []
          extract (x:xs) prev = (x, prev++xs) : extract xs (x : prev)

I want to test it, for example, with

import Test.QuickCheck.Batch    
prop_len l = length l == length (extractions l)
main = runTests "extractions" defOpt [run prop_len]

But this won't compile; I have to supply a type either for run or prop_len, because QuickCheck can't generate [a], it has to generate something concrete. So I chose Int:

main = runTests "extractions" defOpt [r prop_len]
    where r = run :: ([Int] -> Bool) -> TestOptions -> IO TestResult

Is there any way to get QuickCheck to choose a for me instead of having it specified in the type of run?

Giotto answered 15/9, 2008 at 15:59 Comment(0)
B
7

The quickcheck manual says "no":

Properties must have monomorphic types. `Polymorphic' properties, such as the one above, must be restricted to a particular type to be used for testing. It is convenient to do so by stating the types of one or more arguments in a

where types = (x1 :: t1, x2 :: t2, ...)

clause...

Bookbinder answered 15/9, 2008 at 17:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.