Sha256: 35f623fb42e24fd415b7c0f2a3cd454574bb2519f796a5db758a242b38aca3dd

Contents?: true

Size: 857 Bytes

Versions: 32

Compression:

Stored size: 857 Bytes

Contents

class ParallelTests
  class Grouper
    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

    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

    def self.smallest_first(files)
      files.sort_by{|item, size| size }.reverse
    end
  end
end

Version data entries

32 entries across 32 versions & 3 rubygems

Version Path
moxiesoft_parallel_tests-0.4.13 lib/parallel_tests/grouper.rb
parallel_tests-0.6.6 lib/parallel_tests/grouper.rb
parallel_tests-0.6.5 lib/parallel_tests/grouper.rb
parallel_tests-0.6.4 lib/parallel_tests/grouper.rb
parallel_tests-0.6.3 lib/parallel_tests/grouper.rb
parallel_tests-0.6.2 lib/parallel_tests/grouper.rb
phene-parallel_tests-0.6.2 lib/parallel_tests/grouper.rb
parallel_tests-0.6.1 lib/parallel_tests/grouper.rb
parallel_tests-0.6.0 lib/parallel_tests/grouper.rb
parallel_tests-0.5.0 lib/parallel_tests/grouper.rb
parallel_tests-0.4.21 lib/parallel_tests/grouper.rb
parallel_tests-0.4.20 lib/parallel_tests/grouper.rb
parallel_tests-0.4.19 lib/parallel_tests/grouper.rb
parallel_tests-0.4.18 lib/parallel_tests/grouper.rb
parallel_tests-0.4.17 lib/parallel_tests/grouper.rb
parallel_tests-0.4.16 lib/parallel_tests/grouper.rb
parallel_tests-0.4.15 lib/parallel_tests/grouper.rb
parallel_tests-0.4.14 lib/parallel_tests/grouper.rb
parallel_tests-0.4.13 lib/parallel_tests/grouper.rb
moxiesoft_parallel_tests-0.4.12 lib/parallel_tests/grouper.rb