Haskell检查文件中的所有属性
示例
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[]行是必需的。它使文本在该行上方的定义对TemplateHaskell可见。
$ runhaskell QuickCheckAllExample.hs === prop_sortIdempotent from tree.hs:7 === +++ OK, passed 100 tests.
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短