繁体   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