reimplementing break (incorrectly) "quickcheck p list" gives me feedback that it breaks on list, but not what predicate test caused the breakage

I am a total quickcheck noob. Is there a way to find out what predicate test "<function>" is, below? Also, is there a way I can ask quickcheck to test lists of various built in types, not just Int? *********** Falsifiable, after 4 tests: <function> [1] *Recursion> testMyBreak Falsifiable, after 1 tests: <function> [-1,1,2] *Recursion> testMyBreak = quickCheck $ \p l -> myBreak p (l :: [Int]) == break p l myBreak t xs = let f t next rest = if t next then ([], snd rest) else (next : fst rest, snd rest) in foldr ( f t ) ([],[]) xs --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

On Thu, 2007-07-05 at 19:37 -0400, Thomas Hartman wrote:
I am a total quickcheck noob. Is there a way to find out what predicate test "<function>" is, below?
testMyBreak = quickCheck $ \p l -> myBreak p (l :: [Int]) == break p l
Well - you could try naming the qc property? I.e. prop_myBreak p l = myBreak p l == break p l testMyBreak = quickCheck prop_myBreak
Also, is there a way I can ask quickcheck to test lists of various built in types, not just Int?
Yes. You need to declare instances of 'Arbitrary' for custom data types, which allows QuickCheck to manufacture random values of that type. -k PS: Is this use of uPIO legal? Sound? Sensible? prop_serialize (E s) = let [s'] = unsafePerformIO (do writeFasta "/tmp/serialize_test" [s] readFasta "/tmp/serialize_test") in s == s'

On 7/6/07, Thomas Hartman
I am a total quickcheck noob. Is there a way to find out what predicate test "<function>" is, below?
The trick that I know of to do that is to not generate a function in the first place, but a data type which can represent various functions of this type. Whenever we want to use the data type as a function in the test we convert it to a function. Let's take an example: data IntFun = Plus5 | Mult5 deriving show apply :: IntFun -> Int -> Int apply Plus = (+ 5) apply Mult = (* 5) instance Arbitrary IntFun where arbitrary = elements [Plus,Mult] prop_foo f a = apply f a == a Ofcourse the data type will typically be much more complicated depending on what kind of functions you want to be able to generate. This trick is documented in the following paper: http://www.st.cs.ru.nl/papers/2006/koop2006-TestingOfHigherOrderFunctionsAPL... HTH, Josef
participants (3)
-
Josef Svenningsson
-
Ketil Malde
-
Thomas Hartman