vendredi 23 septembre 2016

Random sampling with Hypothesis

In Hypothesis, there is an corresponding sampled_from() strategy to random.choice():

In [1]: from hypothesis import find, strategies as st

In [2]: find(st.sampled_from(('ST', 'LT', 'TG', 'CT')), lambda x: True)
Out[2]: 'ST'

But, is there a way to have random.sample()-like strategy to produce subsequences of length N out of a sequence?

In [3]: import random

In [4]: random.sample(('ST', 'LT', 'TG', 'CT'), 2)
Out[4]: ['CT', 'TG']




Aucun commentaire:

Enregistrer un commentaire