Sha256: 3838205f6f4d22a225b931b80e1c5561079083d4ba6a5e582ed8fb5e036e621c

Contents?: true

Size: 1.34 KB

Versions: 9

Compression:

Stored size: 1.34 KB

Contents

module Bench
  module Utils
    include Logging
    
    def compare(name1,s1,name2,s2)
      r1 = diff([],name1,s1,name2,s2)
      r2 = diff([],name2,s2,name1,s1)
      r1.size > r2.size ? r1 : r2
    end
    
    def diff(res,lname,lvalue,rname,rvalue,path=[])

      return res if lvalue == rvalue
      
      if lvalue.is_a?(Array) and rvalue
        lvalue.each_index do |index| 
          p = Array.new(path)
          p << index
          diff(res,lname,lvalue[index],rname,rvalue.at(index),p)
        end                
      elsif lvalue.is_a?(Hash) and rvalue
        lvalue.each do |key,value| 
          p = Array.new(path)
          p << key
          diff(res,lname,value,rname,rvalue[key],p)
        end
      else            
        res << {:path=>path,lname=>lvalue,rname=>rvalue}
      end
      
      res 
    end
    
    def compare_and_log(expected,actual,caller)
      if expected != actual
        bench_log "#{log_prefix} Verify error at: " + caller
        bench_log "#{log_prefix} Message diff: "
        compare(:expected,expected,:actual,actual).each do |diff|
          bench_log "#{log_prefix} Path: #{diff[:path].join('/')}"
          bench_log "#{log_prefix} Expected: #{diff[:expected].inspect}"
          bench_log "#{log_prefix} Actual: #{diff[:actual].inspect}"
        end
        1
      else
        0
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rhoconnect-3.0.5 bench/lib/bench/utils.rb
rhoconnect-3.0.4 bench/lib/bench/utils.rb
rhoconnect-3.0.3 bench/lib/bench/utils.rb
rhoconnect-3.0.2 bench/lib/bench/utils.rb
rhoconnect-3.0.1 bench/lib/bench/utils.rb
rhoconnect-3.0.0 bench/lib/bench/utils.rb
rhoconnect-3.0.0.rc1 bench/lib/bench/utils.rb
rhoconnect-3.0.0.beta3 bench/lib/bench/utils.rb
rhoconnect-3.0.0.beta1 bench/lib/bench/utils.rb