Method: PropCheck::Generators.fixed_hash

Defined in:
lib/prop_check/generators.rb

.fixed_hash(hash) ⇒ Object

Given a hash where the values are generators, creates a generator that returns hashes with the same keys, and their corresponding values from their corresponding generators.

Shrinks element generators.

>> Generators.fixed_hash(a: Generators.integer(), b: Generators.real_float(), c: Generators.integer()).call(size: 10, rng: Random.new(42))
=> {:a=>-4, :b=>13.0, :c=>-3}


335
336
337
338
339
340
341
342
343
# File 'lib/prop_check/generators.rb', line 335

def fixed_hash(hash)
  keypair_generators =
    hash.map do |key, generator|
      generator.map { |val| [key, val] }
    end

  tuple(*keypair_generators)
    .map(&:to_h)
end