gpt4 book ai didi

haskell - QuickCheck 中的 "size"参数究竟是什么?

转载 作者:行者123 更新时间:2023-12-04 04:12:20 24 4
gpt4 key购买 nike

尺寸 参数在quickcheck中的许多功能中使用。但我很难理解它到底是什么。什么getSize返回?

最佳答案

来自 the manual :

Test data generators have an implicit size parameter; quickCheck begins by generating small test cases, and gradually increases the size as testing progresses. Different test data generators interpret the size parameter in different ways: some ignore it, while the list generator, for example, interprets it as an upper bound on the length of generated lists. You are free to use it as you wish to control your own test data generators.

You can obtain the value of the size parameter using

sized :: (Int -> Gen a) -> Gen a

sized g calls g, passing it the current size as a parameter. For example, to generate natural numbers in the range 0 to size, use

sized $ \n -> choose (0, n)

The purpose of size control is to ensure that test cases are large enough to reveal errors, while remaining small enough to test fast.


getSize只是获取该大小参数的另一种方法。请注意 getSize相当于 sized pure , 和 sized相当于 (getSize >>=) .

关于haskell - QuickCheck 中的 "size"参数究竟是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61491378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com