class ParallelTests::Test::Runner

def sort_by_runtime(tests, runtimes, options={})

def sort_by_runtime(tests, runtimes, options={})
  allowed_missing = options[:allowed_missing] || 1.0
  allowed_missing = tests.size * allowed_missing
  # build runtime hash
  times = {}
  runtimes.each do |line|
    test, time = line.split(":", 2)
    next unless test and time
    times[test] = time.to_f
  end
  # set know runtime for each test
  tests.sort!
  tests.map! do |test|
    allowed_missing -= 1 unless time = times[test]
    raise "Too little runtime info" if allowed_missing < 0
    [test, time]
  end
  if options[:verbose]
    puts "Runtime found for #{tests.count(&:last)} of #{tests.size} tests"
  end
  # fill gaps with average runtime
  known, unknown = tests.partition(&:last)
  average = known.map!(&:last).inject(:+) / known.size
  unknown.each { |set| set[1] = average }
end