Class: ParallelTests::Grouper
- Inherits:
-
Object
- Object
- ParallelTests::Grouper
- Defined in:
- lib/parallel_tests/grouper.rb
Class Method Summary collapse
- .in_even_groups_by_size(items_with_sizes, num_groups) ⇒ Object
- .in_groups(items, num_groups) ⇒ Object
- .smallest_first(files) ⇒ Object
Class Method Details
.in_even_groups_by_size(items_with_sizes, num_groups) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/parallel_tests/grouper.rb', line 14 def self.in_even_groups_by_size(items_with_sizes, num_groups) items_with_size = smallest_first(items_with_sizes) groups = Array.new(num_groups){{:items => [], :size => 0}} items_with_size.each do |item, size| # always add to smallest group smallest = groups.sort_by{|g| g[:size] }.first smallest[:items] << item smallest[:size] += size end groups.map{|g| g[:items] } end |
.in_groups(items, num_groups) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/parallel_tests/grouper.rb', line 3 def self.in_groups(items, num_groups) [].tap do |groups| while ! items.empty? (0...num_groups).map do |group_number| groups[group_number] ||= [] groups[group_number] << items.shift end end end end |
.smallest_first(files) ⇒ Object
27 28 29 |
# File 'lib/parallel_tests/grouper.rb', line 27 def self.smallest_first(files) files.sort_by{|item, size| size }.reverse end |