haskell - 在 Hedgehog 中通过 'Gen' 或通过 'forAll' 生成随机输入的区别

标签 haskell testing automated-tests property-based-testing haskell-hedgehog

假设,我想测试 Sum 的以下关联性属性在hedgehog的帮助下Haskell 中的库:

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 问题下回答了这个问题:

关于haskell - 在 Hedgehog 中通过 'Gen' 或通过 'forAll' 生成随机输入的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49711248/

相关文章:

c# - 测试 Microsoft Surface 应用程序的最佳方式

html - 检查元素是否有 child

testing - Hudson/Jenkins 仅在连续失败时通知

c - 裸机 C 代码(微处理器固件): simulating changes in hardware registers 的自动化测试

haskell - 在 Haskell 程序之间传递数据

haskell - 如何/可以将此类型制成 Monoid 实例

haskell - 共享可变状态: when to use IORefs

haskell - Cabal 安装的软件包缓存清理问题

testing - 如何对网站进行负载测试?

python - 使用 pywinauto 查找 qwidget 对象文本