Python hypothesis.strategies.randoms() Examples
The following are 2
code examples of hypothesis.strategies.randoms().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hypothesis.strategies
, or try the search function
.
Example #1
Source File: dataset_strategy.py From segpy with GNU Affero General Public License v3.0 | 5 votes |
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
Example #2
Source File: test.py From lkpy with MIT License | 5 votes |
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))