class SimpleCov::CoverageStatistics

  • strength - average hits per/coverable (will not exist for one shot lines format)
    * percent - percentage as covered/missed
    * omitted - how many lines cannot be covered (blank lines/comments); only meaningful for line coverage
    * missed - how many of the coverables are missed
    * covered - how many of the coverables are hit
    * total - how many things to cover there are (total relevant loc/branches)
    This is uniform across coverage criteria as they all have:
    Holds the individual data of a coverage result.

def self.from(coverage_statistics)

def self.from(coverage_statistics)
  sum_covered, sum_missed, sum_omitted, sum_total_strength =
    coverage_statistics.reduce([0, 0, 0, 0.0]) do |(covered, missed, omitted, total_strength), stats|
      [
        covered + stats.covered,
        missed + stats.missed,
        omitted + stats.omitted,
        # gotta remultiply with loc because files have different strength and loc
        # giving them a different "weight" in total
        total_strength + (stats.strength * stats.total)
      ]
    end
  new(covered: sum_covered, missed: sum_missed, omitted: sum_omitted, total_strength: sum_total_strength)
end

def compute_percent(covered, missed, total)

def compute_percent(covered, missed, total)
  return 100.0 if missed.zero?
  covered * 100.0 / total
end

def compute_strength(total_strength, total)

def compute_strength(total_strength, total)
  return 0.0 if total.zero?
  total_strength.to_f / total
end

def initialize(covered:, missed:, omitted: 0, total_strength: 0.0, percent: nil)

Other values are computed by this class.

Requires only covered, missed and strength to be initialized.
def initialize(covered:, missed:, omitted: 0, total_strength: 0.0, percent: nil)
  @covered  = covered
  @missed   = missed
  @omitted  = omitted
  @total    = covered + missed
  @percent  = percent || compute_percent(covered, missed, total)
  @strength = compute_strength(total_strength, total)
end