簡體   English   中英

在Hedgehog中通過'Gen'或'forAll'生成隨機輸入之間的區別

[英]Difference between generating random input through 'Gen' or through 'forAll' in Hedgehog

假設,我想在Haskell的hedgehog庫的幫助下測試Sum的以下關聯屬性:

a <> (b <> c) ≡ (a <> b) <> c

我實際上有兩種方法來生成隨機輸入。

1.在Gen生成所有內容(使用Gen的Applicative和Monad實例)

genTriple :: Get (Int, Int, Int)
genTriple = liftA3 (,,) Gen.enumBounded Gen.enumBounded Gen.enumBounded

prop_assoc :: Property
prop_assoc = property $ do
  (a, b, c) <- forAll genTriple
  (Sum a <> Sum b) <> Sum c === Sum a <> (Sum b <> Sum c)

2.在forAll下生成每個字段

prop_assoc :: Property
prop_assoc = property $ do
  a <- forAll Gen.enumBounded
  b <- forAll Gen.enumBounded
  c <- forAll Gen.enumBounded
  (Sum a <> Sum b) <> Sum c === Sum a <> (Sum b <> Sum c)

我想知道,兩種方法有什么區別? 它是否以某種方式影響性能或並行化或隨機性?

包維護者在相應的GitHub問題下回答了這個問題:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM