Module: AssertRandom::AssertionMixins

Defined in:
lib/assert-random.rb

Instance Method Summary collapse

Instance Method Details

#assert_random(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/assert-random.rb', line 6

def assert_random(options = {})
  _wrap_assertion do
    assert_block("assert needs to be called with a block.") { block_given? }  
    configuration = { :tolerance => 1, :iterations => 10 }
    configuration.merge!(options) if options.is_a?(Hash)        
    assert_block("No point running with an iteration count of 1") { !only_iterating_once? configuration[:iterations] } 
    
    results = Array.new
    configuration[:iterations].times do
      results.push yield
    end
    
    assert_block("#{configuration[:tolerance]} or more values match") { !same_values? results, configuration[:tolerance] } 
    assert_block("Results are in a sequence") { !in_sequence? results } 
  end
end