Haskell,IO,monads,quickcheck [英] Haskell, IO, monads, quickcheck
问题描述
我有一个函数,还有一些属性用于测试我用quickcheck编写的代码。这些属性在我在解释器中单独运行它们时起作用,并且函数检出正常。然而,手动快速检查解释器中的每个属性(quickCheck prop_this, quickCheck prop_that)无聊,单调,耗时。我想将所有这些都放在一个程序中,并让该程序运行所有的快速检查。这是我卡住的地方。
该程序的基本框架如下:
进口...
function_which_i_want_to_quickcheck
prop_1
prop_2
等...
main = do
quickCheck prop_1
quickCheck prop_2
etc ...
我相信所有高于主要的东西都是好的,因为它全部在没有它的情况下编译和工作。主要是我需要帮助。我尝试了几个变体,即没有做,使用do,使用'x< - quickCheck y'分配结果,从内部移除quickCheck并将其粘在外部,等等,但不能得到任何东西
$ b
-
任何人都可以协助完成上述工作吗?
$ b如果我想将main中的所有内容移动到另一个(正常,非主要)函数,我该如何去做? $ b
编辑:我很欣赏测试框架的建议,但我在这里要求的是在任何其他语言中做的微不足道,并且不应该需要测试框架。为什么不是Haskell?
另外,这在解释器内部正确工作。我无法在主内部工作。任何想法为什么?
quickCheck prop_1>> quickCheck prop_2>> quickCheck prop_3
谢谢。
这个问题不是很清楚你有什么问题,但通常我会推荐使用测试框架,比如 要运行这个,你需要安装 它在执行时看起来如何: Beginner at Haskell here. I have a function, and a bunch of properties to test it with which I've written using quickcheck. The properties work when I run them individually in the interpreter, and the function checks out fine. However, manually quickchecking with each property in the interpreter by hand (quickCheck prop_this, quickCheck prop_that) is boring, monotonous, and time-consuming. I would like to stick all of this in a program, and have that program run all of the quickchecks. This is where I am stuck. The basic skeleton of the program is as follows: Everything above main is fine I believe, as it all compiles and works without it. main is what I need help with. I've tried several variations, i.e. not having a do, using a do, assigning results using 'x <- quickCheck y', removing quickCheck from the inside and sticking it on the outside instead, etc. but can't get anything to work. Can anyone assist with the above? If I wanted to move everything inside main to another (normal, non-main) function, how would I do it? EDIT: I appreciate the recommendation for testing frameworks, but what I'm asking for here is trivial to do in any other language, and shouldn't need a testing framework. Why not Haskell? Also, this works correctly right inside the interpreter. I can't get it to work inside main. Any ideas why? Thanks. It is not very clear from the question what problems you have, but generally I'd recommend using a testing framework, such as tasty, to organize your quickcheck tests together: To run this, you'll need to install the Here's how it looks when executed: 这篇关于Haskell,IO,monads,quickcheck的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
import Test.Tasty
import Test.Tasty.QuickCheck
$ b $ main = defaultMain $ testGroupTests
[testProperty+是可交换的$
\xy - > x + y ==(y + x :: Double)
,testProperty+是关联的$
\ x y z - > (x + y)+ z ==(x +(y + z):: Double)
]
tasty-quickcheck
包。
imports...
function_which_i_want_to_quickcheck
prop_1
prop_2
etc...
main = do
quickCheck prop_1
quickCheck prop_2
etc...
quickCheck prop_1 >> quickCheck prop_2 >> quickCheck prop_3
import Test.Tasty
import Test.Tasty.QuickCheck
main = defaultMain $ testGroup "Tests"
[ testProperty "+ is commutative" $
\x y -> x + y == (y + x :: Double)
, testProperty "+ is associative" $
\x y z -> (x + y) + z == (x + (y + z) :: Double)
]
tasty-quickcheck
package.