class MutatorRails::Statistics

Attributes

content[R]
stats[R]

Public Instance Methods

call() click to toggle source
# File lib/mutator_rails/statistics.rb, line 9
def call
  @content = ListMaker.new.make_list.map(&:details)

  @stats = []
  total_mutations
  fully_mutated
  failures
  fallback_to_j1
  top_10_alive
  top_10_longest
  top_10_total_mutations

  puts " ... storing #{stats_file}"
  puts text
  File.write(stats_file, text)
end

Private Instance Methods

alive_pct() click to toggle source
# File lib/mutator_rails/statistics.rb, line 182
def alive_pct
  100.0 * total_alive / tot_mutations
end
failure_header() click to toggle source
# File lib/mutator_rails/statistics.rb, line 49
def failure_header
  stats << ''
  stats << "The following modules remain with failures (check log):"
end
failures() click to toggle source
# File lib/mutator_rails/statistics.rb, line 33
def failures
  header = false
  l = []
  content.each do |detail|
    failure = detail[7]
    if failure
      unless header
        failure_header
        header = true
      end
      l << " . " + detail[0]
    end
  end
  @stats += l.sort if l.any?
end
fallback_to_j1() click to toggle source
# File lib/mutator_rails/statistics.rb, line 54
def fallback_to_j1
  header = false
  l = []
  content.each do |detail|
    failure = detail[8]
    if failure.eql?(1)
      unless header
        j1_header
        header = true
      end
      l << " . " + detail[0]
    end
  end
  @stats += l.sort if l.any?
end
full_mutations() click to toggle source
# File lib/mutator_rails/statistics.rb, line 120
def full_mutations
  tot = 0
  content.each do |detail|
    alive = detail[2]
    tot   += 1 if alive&.zero?
  end
  tot
end
fully_mutated() click to toggle source
# File lib/mutator_rails/statistics.rb, line 28
def fully_mutated
  stats << ''
  stats << "#{full_mutations} module(s) were fully mutated (#{fully_pct.round(1)}%)"
end
fully_pct() click to toggle source
# File lib/mutator_rails/statistics.rb, line 129
def fully_pct
  100.0 * full_mutations / content.size
end
humanize(secs) click to toggle source
# File lib/mutator_rails/statistics.rb, line 159
def humanize(secs)
  [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map { |count, name|
    if secs > 0
      secs, n = secs.divmod(count)
      "#{n.to_i} #{n.to_i.eql?(1) ? name.to_s.chop : name}"
    end
  }.compact.reverse.join(' ')
end
j1_header() click to toggle source
# File lib/mutator_rails/statistics.rb, line 70
def j1_header
  stats << ''
  stats << "The following modules fell back to non-parallel(-j1):"
end
killed_pct() click to toggle source
# File lib/mutator_rails/statistics.rb, line 186
def killed_pct
  100.0 * total_kills / tot_mutations
end
per_sec() click to toggle source
# File lib/mutator_rails/statistics.rb, line 155
def per_sec
  tot_mutations.to_f / total_seconds
end
stats_file() click to toggle source
# File lib/mutator_rails/statistics.rb, line 190
def stats_file
  MutatorRails::Config.configuration.statistics
end
text() click to toggle source
# File lib/mutator_rails/statistics.rb, line 108
def text
  stats.join("\n")
end
top_10_alive() click to toggle source
# File lib/mutator_rails/statistics.rb, line 75
def top_10_alive
  stats << ''
  stats << "The following modules had most alive mutations (top 10):"
  content.sort_by { |d| -d[2].to_i }.take(10).each do |detail|
    alive = detail[2]
    if alive.positive?
      stats << " . #{detail[0]} (#{alive})"
    end
  end
end
top_10_longest() click to toggle source
# File lib/mutator_rails/statistics.rb, line 86
def top_10_longest
  stats << ''
  stats << "The following modules had longest mutation time (top 10):"
  content.sort_by { |d| -d[6].to_i }.take(10).each do |detail|
    time = detail[6]
    if time&.positive?
      stats << " . #{detail[0]} (#{humanize(time.to_i)})"
    end
  end
end
top_10_total_mutations() click to toggle source
# File lib/mutator_rails/statistics.rb, line 97
def top_10_total_mutations
  stats << ''
  stats << "The following modules had largest mutation count (top 10):"
  content.sort_by { |d| -d[3].to_i }.take(10).each do |detail|
    cnt = detail[3]
    if cnt&.positive?
      stats << " . #{detail[0]} (#{cnt})"
    end
  end
end
tot_mutations() click to toggle source
# File lib/mutator_rails/statistics.rb, line 169
def tot_mutations
  tot = 0
  content.each do |detail|
    total = detail[3]
    tot   += total.to_i
  end
  tot
end
total_alive() click to toggle source
# File lib/mutator_rails/statistics.rb, line 133
def total_alive
  tot = 0
  content.each do |detail|
    alive = detail[2]
    tot   += alive.to_i
  end
  tot
end
total_kills() click to toggle source
# File lib/mutator_rails/statistics.rb, line 178
def total_kills
  tot_mutations - total_alive
end
total_mutation_time() click to toggle source
# File lib/mutator_rails/statistics.rb, line 142
def total_mutation_time
  humanize(total_seconds.to_i)
end
total_mutations() click to toggle source
# File lib/mutator_rails/statistics.rb, line 112
def total_mutations
  stats << ''
  stats << "#{content.size} module(s) were mutated in #{total_mutation_time}"
  stats << "for a total of #{tot_mutations} mutations tested @ #{per_sec.round(2)}/sec average"
  stats << "which left #{total_alive} mutations alive (#{alive_pct.round(1)}%)"
  stats << "and #{total_kills} killed (#{killed_pct.round(1)}%)"
end
total_seconds() click to toggle source
# File lib/mutator_rails/statistics.rb, line 146
def total_seconds
  tot = 0.0
  content.each do |detail|
    runtime = detail[6]
    tot     += runtime if runtime
  end
  tot
end