quickCheckAll是Haskell模板帮助程序,可在当前文件中查找名称以其开头的所有定义prop_并进行测试。
{-# LANGUAGE TemplateHaskell #-} importTest.QuickCheck(quickCheckAll) importData.List(sort) idempotent :: Eq a => (a -> a) -> a -> Bool idempotent f x = f (f x) == f x prop_sortIdempotent = idempotent sort -- does not begin with prop_, will not be picked up by the test runner sortDoesNotChangeLength xs = length (sort xs) == length xs return [] main = $quickCheckAll
请注意,该return []行是必需的。它使文本在该行上方的定义对Template Haskell可见。
$ runhaskell QuickCheckAllExample.hs === prop_sortIdempotent from tree.hs:7 === +++ OK, passed 100 tests.