Class: SimpleCov::CoverageStatistics
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/simplecov/coverage_statistics.rb |
Overview
Holds the individual data of a coverage result.
This is uniform across coverage criteria as they all have:
-
total - how many things to cover there are (total relevant loc/branches)
-
covered - how many of the coverables are hit
-
missed - how many of the coverables are missed
-
percent - percentage as covered/missed
-
strength - average hits per/coverable (will not exist for one shot lines format)
Class Method Summary
- .from(coverage_statistics)
-
.new(covered:, missed:, total_strength: 0.0) ⇒ CoverageStatistics
constructor
Requires only covered, missed and strength to be initialized.
Instance Attribute Summary
Instance Method Summary
Constructor Details
.new(covered:, missed:, total_strength: 0.0) ⇒ CoverageStatistics
Requires only covered, missed and strength to be initialized.
Other values are computed by this class.
# File 'lib/simplecov/coverage_statistics.rb', line 34
def initialize(covered:, missed:, total_strength: 0.0) @covered = covered @missed = missed @total = covered + missed @percent = compute_percent(covered, missed, total) @strength = compute_strength(total_strength, total) end
Class Method Details
.from(coverage_statistics)
[ GitHub ]# File 'lib/simplecov/coverage_statistics.rb', line 16
def self.from(coverage_statistics) sum_covered, sum_missed, sum_total_strength = coverage_statistics.reduce([0, 0, 0.0]) do |(covered, missed, total_strength), file_coverage_statistics| [ covered + file_coverage_statistics.covered, missed + file_coverage_statistics.missed, # gotta remultiply with loc because files have different strength and loc # giving them a different "weight" in total total_strength + (file_coverage_statistics.strength * file_coverage_statistics.total) ] end new(covered: sum_covered, missed: sum_missed, total_strength: sum_total_strength) end