Have a Strategy that does not uniformly choose between different strategies

爷,独闯天下 提交于 2019-12-13 04:23:16

问题


I'd like to create a strategy C that, 90% of the time chooses strategy A, and 10% of the time chooses strategy B.

The random python library does not work even if I seed it since each time the strategy produces values, it generates the same value from random.

I looked at the implementation for OneOfStrategy and they use i = cu.integer_range(data, 0, n - 1) to randomly generate a number

cu is from the internals import hypothesis.internal.conjecture.utils as cu

Would it be fine for my strategy to use cu.integer_range or is there another implementation?


回答1:


Hypothesis does not allow users to control the probability of various choices within a strategy. You should not use undocumented interfaces either - hypothesis.internal is for internal use only and could break at any time!

I strongly recommend using C = st.one_of(A, B) and trusting Hypothesis with the details.



来源:https://stackoverflow.com/questions/49827010/have-a-strategy-that-does-not-uniformly-choose-between-different-strategies

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