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 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短