Property-based testing
import Test.QuickCheck
reverse :: [a] -> [a]
double_reverse xs = reverse (reverse xs) == xs
Standard run
Prelude Test.QuickCheck> quickCheck double_reverse
+++ OK, passed 100 tests.
Version for the curious
Prelude Test.QuickCheck> verboseCheck double_reverse
Passed:
[]
Passed:
[]
Passed:
[()]
Passed:
[(),()]
Passed:
[(),(),(),()]
...
Passed:
[(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),()]
+++ OK, passed 100 tests.
Also try
verboseCheck (prop_reverse :: [Int] -> Bool)
sumAbs = sum . map abs
prop_sumAbs xs = sumAbs xs == sum xs
It fails, who knew...
quickCheck prop_sumAbs
*** Failed! Falsifiable (after 4 tests and 2 shrinks):
[-1]