She*_*rsh 7 testing automated-tests haskell property-based-testing haskell-hedgehog
假设,我想在Haskell Sum的hedgehog库的帮助下测试以下的associativity属性:
a <> (b <> c) ? (a <> b) <> c
Run Code Online (Sandbox Code Playgroud)
我实际上有两种方法来生成随机输入.
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)
Run Code Online (Sandbox Code Playgroud)
forAllprop_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)
Run Code Online (Sandbox Code Playgroud)
我想知道,两种方法有什么区别?它是否以某种方式影响性能或并行化或随机性?