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
-
MAX_32_BIT =
# File 'rspec-core/lib/rspec/core/ordering.rb', line 584_294_967_295
Class Method Summary
- .new(configuration) ⇒ Random constructor Internal use only
Instance Attribute Summary
- #used? ⇒ Boolean readonly Internal use only
Instance Method Summary
- #order(items) Internal use only
-
#jenkins_hash_digest(string)
private
Internal use only
en.wikipedia.org/wiki/Jenkins_hash_function Jenkins provides a good distribution and is simpler than MD5.
Instance Attribute Details
#used? ⇒ Boolean
(readonly)
# 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.
# 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