I would like to use QuickCheck to test a function to make sure it terminates (no infinite recursion, no exceptions thrown, etc.). This is what I do at the moment:
f :: Int -> Int -> Int
prop_fTerminates :: Int -> Int -> Bool -- say
prop_fTerminates x y = f x y `seq` True
Is there a better (more expressive and idiomatic) way?
I probably wouldn't bother, I'd just test other properties of its output.
Any property that examines the output of f x y
in any way is going to do at least as much termination checking as your prop_fTerminates
, so why waste time doubling up on that check?
If for some reason "f x y terminates" is the only property you can test about f
, then what you've got seems reasonable.