【发布时间】:2020-01-16 08:10:49
【问题描述】:
如何在 Haskell QuickCheck 中生成一个随机实例,然后在这个实例上运行进一步的测试?
让我举个例子来说明。在下面的代码 sn-p 中,我生成了一个 Int,然后想在这个 Int 上运行进一步的测试:
{-# OPTIONS -Wall #-}
import Test.Tasty
import Test.Tasty.QuickCheck as QC
import qualified Debug.Trace as Trace
main :: IO()
main = defaultMain tests
test1 :: Int -> Property
test1 i = withMaxSuccess 2 (test2 i)
test2 :: Int -> (Int, Int) -> Property
test2 i (a, b) =
Trace.trace ("(n,a,b) = " ++ show (i, a, b)) $
property True
tests :: TestTree
tests =
testGroup
"Test suite"
[
QC.testProperty "Test" (withMaxSuccess 3 test1)
]
作为输出,我想要类似的东西:
(n,a,b) = (0,0,0)
(n,a,b) = (0,1,2)
(n,a,b) = (-1,-1,-1)
(n,a,b) = (-1,-2,-3)
(n,a,b) = (2,0,-2)
(n,a,b) = (2,1,-1)
但是我得到了:
(n,a,b) = (0,0,0)
(n,a,b) = (-1,-1,-1)
(n,a,b) = (2,0,-2)
我找到了这个post (How can QuickCheck test all properties for each sample),但它并没有真正帮助我。
【问题讨论】:
标签: haskell testing quickcheck