Class: Pbt::Arbitrary::FixedHashArbitrary
- Defined in:
- lib/pbt/arbitrary/fixed_hash_arbitrary.rb
Overview
Generates a hash with fixed keys and arbitrary values.
Instance Method Summary collapse
- #generate(rng) ⇒ Object
-
#initialize(hash) ⇒ FixedHashArbitrary
constructor
A new instance of FixedHashArbitrary.
- #shrink(current) ⇒ Object
Methods inherited from Arbitrary
Constructor Details
permalink #initialize(hash) ⇒ FixedHashArbitrary
Returns a new instance of FixedHashArbitrary.
8 9 10 11 |
# File 'lib/pbt/arbitrary/fixed_hash_arbitrary.rb', line 8 def initialize(hash) @keys = hash.keys @arb = TupleArbitrary.new(*hash.values) end |
Instance Method Details
permalink #generate(rng) ⇒ Object
14 15 16 17 |
# File 'lib/pbt/arbitrary/fixed_hash_arbitrary.rb', line 14 def generate(rng) values = @arb.generate(rng) @keys.zip(values).to_h end |
permalink #shrink(current) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/pbt/arbitrary/fixed_hash_arbitrary.rb', line 20 def shrink(current) # This is not the most comprehensive but allows a reasonable number of entries in the shrink Enumerator.new do |y| @arb.shrink(current.values).each do |next_values| y << @keys.zip(next_values).to_h end end end |