123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Core::Ordering::Random Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: rspec-core/lib/rspec/core/ordering.rb

Overview

Orders items randomly.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#used?Boolean (readonly)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/ordering.rb', line 21

def used?
  @used
end

Instance Method Details

#jenkins_hash_digest(string) (private)

en.wikipedia.org/wiki/Jenkins_hash_function Jenkins provides a good distribution and is simpler than MD5. It’s a bit slower than MD5 (primarily because Digest::MD5 is implemented in C) but has the advantage of not requiring us to load another part of stdlib, which we try to minimize.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/ordering.rb', line 39

def jenkins_hash_digest(string)
  hash = 0

  string.each_byte do |byte|
    hash += byte
    hash &= MAX_32_BIT
    hash += ((hash << 10) & MAX_32_BIT)
    hash &= MAX_32_BIT
    hash ^= hash >> 6
  end

  hash += ((hash << 3) & MAX_32_BIT)
  hash &= MAX_32_BIT
  hash ^= hash >> 11
  hash += ((hash << 15) & MAX_32_BIT)
  hash &= MAX_32_BIT
  hash
end

#order(items)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/ordering.rb', line 25

def order(items)
  @used = true

  seed = @configuration.seed.to_s
  items.sort_by { |item| jenkins_hash_digest(seed + item.id) }
end