How can QuickCheck test all properties for each sample

天大地大妈咪最大 提交于 2021-02-07 19:22:15

问题


...instead of generating 100 new random samples for each property?

My testsuite contains the TemplateHaskell hack explained here [1] to test all functions named prop_*. Running the test program prints

=== prop_foo from tests/lala.lhs:20 ===
+++ OK, passed 100 tests.

=== prop_bar from tests/lala.lhs:28 ===
+++ OK, passed 100 tests.

and it looks like going through 100 random samples for each of the properties.

Problemis: Generating the samples is quite expensive, checking the properties is not. So I'd like to have a means to pass each random sample to each of the prop_* functions instead of creating new (#properties * 100) many samples.

Is there anything like that built in? Actually, I think I'd need a replacement for the splice

$(forAllProperties)

in

main :: IO ()
main
  = do args <- parseArgs <$> getArgs
       s <- $(forAllProperties) $ quickCheckWithResult args
       s ? return () $ exitFailure
  where
    parseArgs as
      = null as ? stdArgs $ stdArgs{ maxSuccess = read $ head as }

[1] Simple haskell unit testing, and QuickCheck exit status on failures, and cabal integration


回答1:


In this post you can see how to group tests

Stackoverflow post

That user provides a very simple example of use Test.Tasty.QuickCheck

Using testProperty and testGroup you can pass each random sample to each property

In the next link you can check the hackage of this package

Test.Tasty.QuickCheck



来源:https://stackoverflow.com/questions/38233443/how-can-quickcheck-test-all-properties-for-each-sample

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!