仅供参考,这里是一个涉及列表的示例:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
notLargeOrBothNotEmpty :: Property
notLargeOrBothNotEmpty = property $ do
xs <- forAll randomIntLists
ys <- forAll randomIntLists
assert $ length xs < 4 && (xs /= [] && ys /=[])
where
randomIntLists = Gen.frequency
[ (1, Gen.list (Range.constant 0 1) randomInt)
, (10, Gen.list (Range.constant 1 100) randomInt)
]
randomInt = Gen.integral (Range.constat 1 10)
main :: IO Bool
main = checkParallel $
Group "Test.Example" [("Produce a minimal counter-example", notLargeOrBothNotEmpty)]
所以刺猬有时会返回列表作为反例( [ 1 , 1 , 1 , 1 ], [])
。然而([], [])
,是一个较小的反例(有时也由 报告hedgehog
)。</p>
在这种情况下,违反属性的条件是:
4 <= length xs || (xs == [] && ys == [])
如果最初找到一个反例,其中ys /= []
和4 <= length xs
,集成收缩方法将首先尝试收缩xs
,然后继续收缩ys
保持xs
不变,如我在原始问题中引用的帖子中所述。