Method: PropCheck::Generators.set
- Defined in:
- lib/prop_check/generators.rb
.set(element_generator, min: 0, max: nil, empty: true) ⇒ Object
Generates a set of elements, where each of the elements is generated by element_generator.
Shrinks to smaller sets (with shrunken elements). Accepted keyword arguments:
empty: When false, behaves the same as ‘min: 1` min: Ensures at least this many elements are generated. (default: 0) max: Ensures at most this many elements are generated. When nil, an arbitrary count is used instead. (default: nil)
In the set, elements are always unique. If it is not possible to generate another unique value after the configured max_consecutive_attempts a PropCheck::Errors::GeneratorExhaustedError will be raised.
>> Generators.set(Generators.positive_integer).sample(5, size: 4, rng: Random.new(42))
=> [Set[2, 4], Set[], Set[3, 4], Set[], Set[4]]
458 459 460 |
# File 'lib/prop_check/generators.rb', line 458 def set(element_generator, min: 0, max: nil, empty: true) array(element_generator, min: min, max: max, empty: empty, uniq: true).map(&:to_set) end |