Class: DFuzz::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/dfuzz/block.rb

Overview

Serially generate each variable in turn (equivalent to recursively nesting generators)

Instance Method Summary collapse

Constructor Details

#initialize(defaults, generators) ⇒ Block

Returns a new instance of Block.



5
6
7
8
# File 'lib/dfuzz/block.rb', line 5

def initialize(defaults, generators)
  @defaults = defaults
  @generators = generators
end

Instance Method Details

#run(&block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dfuzz/block.rb', line 10

def run(&block)
  generators_index = 0

  # Baseline
  block.call(@defaults)

  # Iterate through generators, fully exhausting each and
  # calling the code block with each set of values
  @generators.each { |g|
    values = Array.new(@defaults)
    while (g.next?)
      values[generators_index] = g.next
      block.call(values)
    end
    generators_index += 1;
  }
end