What is the most efficient way of requiring rather than that all elements generated according to a hypothesis
strategy are unique, at least a certain portion are unique?
Strategies such as the following appear to be inefficient when multiply composed partly because of the unique=True
condition. In this case, it matters that at least a certain portion of the elements are unique rather than that all are.
def base_float(
min_value=None,
max_value=None,
*,
allow_nan=False,
allow_infinity=False,
allow_subnormal=False,
):
"""Strategy for returning a float."""
return st.floats(
min_value=min_value,
max_value=max_value,
allow_nan=allow_nan,
allow_infinity=allow_infinity,
allow_subnormal=allow_subnormal,
)
@st.composite
def plaus_arr(draw, size=None, bounds=ARR_LEN):
size = draw(st.integers(*bounds)) if size is None else size
areas = draw(st_np.arrays(float, size, elements=base_float(), unique=True))
return areas
Is the best approach some modification of the approach suggested here?