setWithLengthInRange<T> method
- @Deprecated('This generator is deprecated and will be removed in 2.0.0.' "It's not possible to reliably generate sets with a given length. For " 'example, any.setWithLengthInRange(3, 10, any.bool) is impossible.')
A generator that returns Sets with a length
that is between min
and
max
.
Implementation
@core.Deprecated('This generator is deprecated and will be removed in 2.0.0.'
"It's not possible to reliably generate sets with a given length. For "
'example, any.setWithLengthInRange(3, 10, any.bool) is impossible.')
Generator<core.Set<T>> setWithLengthInRange<T>(
core.int? min,
core.int? max,
Generator<T> item,
) {
final actualMin = min ?? 0;
assert(actualMin >= 0);
return (random, size) {
final length = random.nextIntInRange(
actualMin,
math.max(max ?? size, actualMin + 1),
);
// TODO(marcelgarus): Make sure the same item is not added twice.
return ShrinkableSet(
<Shrinkable<T>>{for (var i = 0; i < length; i++) item(random, size)},
actualMin,
);
};
}