本文整理汇总了Python中hypothesis.strategies.randoms方法的典型用法代码示例。如果您正苦于以下问题:Python strategies.randoms方法的具体用法?Python strategies.randoms怎么用?Python strategies.randoms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hypothesis.strategies
的用法示例。
在下文中一共展示了strategies.randoms方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extended_textual_header
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import randoms [as 别名]
def extended_textual_header(draw, count=-1, end_text_stanza_probability=None):
if count == -1:
if end_text_stanza_probability is not None:
raise ValueError("end_text_stanza_probability {} does not make sense when count is not {}"
.format(end_text_stanza_probability, count))
count = draw(integers(min_value=0, max_value=10))
headers = draw(lists(stanza(),
min_size=count,
max_size=count))
headers.append(END_TEXT_STANZA)
return headers
if count == 0:
return []
# For counted headers, the end-text stanza is optional. We generate it
# with the specified probability
if end_text_stanza_probability is None:
end_text_stanza_probability = 0.5
random = draw(randoms())
x = random.uniform(0.0, 1.0)
num_data_stanzas = count - 1 if x <= end_text_stanza_probability else count
headers = draw(lists(stanza(),
min_size=num_data_stanzas,
max_size=num_data_stanzas))
if num_data_stanzas == count - 1:
headers.append(END_TEXT_STANZA)
assert len(headers) == count
return headers
示例2: csrs
# 需要导入模块: from hypothesis import strategies [as 别名]
# 或者: from hypothesis.strategies import randoms [as 别名]
def csrs(draw, nrows=None, ncols=None, nnz=None, values=None):
if ncols is None:
ncols = draw(st.integers(5, 100))
elif not isinstance(ncols, int):
ncols = draw(ncols)
if nrows is None:
nrows = draw(st.integers(5, 100))
elif not isinstance(nrows, int):
nrows = draw(nrows)
if nnz is None:
nnz = draw(st.integers(10, nrows * ncols // 2))
elif not isinstance(nnz, int):
nnz = draw(nnz)
coords = draw(nph.arrays(np.int32, nnz, elements=st.integers(0, nrows*ncols - 1), unique=True))
rows = np.mod(coords, nrows, dtype=np.int32)
cols = np.floor_divide(coords, nrows, dtype=np.int32)
if values is None:
values = draw(st.booleans())
if values:
rng = draw(st.randoms())
vals = np.array([rng.normalvariate(0, 1) for i in range(nnz)])
else:
vals = None
return matrix.CSR.from_coo(rows, cols, vals, (nrows, ncols))