Class: SimpleCov::CoverageStatistics
- Inherits:
-
Object
- Object
- SimpleCov::CoverageStatistics
- Defined in:
- lib/simplecov/coverage_statistics.rb,
sig/simplecov.rbs
Overview
Uniform per-criterion coverage statistics. Counts are Integers;
percent and strength are Floats. percent is 100.0 whenever nothing
was missed, including the 0-of-0 case; strength is 0.0 when there
is nothing to cover.
Constant Summary collapse
- ZERO_STATS =
Seed for the reduce in .from: covered, missed, omitted, strength.
[0, 0, 0, 0.0].freeze
Instance Attribute Summary collapse
-
#covered ⇒ Integer
readonly
Returns the value of attribute covered.
-
#missed ⇒ Integer
readonly
Returns the value of attribute missed.
-
#omitted ⇒ Integer
readonly
Returns the value of attribute omitted.
-
#percent ⇒ Float
readonly
Returns the value of attribute percent.
-
#strength ⇒ Float
readonly
Returns the value of attribute strength.
-
#total ⇒ Integer
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
- #compute_percent(covered, missed, total) ⇒ Float
- #compute_strength(total_strength, total) ⇒ Float
-
#initialize(covered:, missed:, omitted: 0, total_strength: 0.0, percent: nil) ⇒ CoverageStatistics
constructor
percent:overrides the computed percentage (used to report 0% for tracked-but-never-loaded files).
Constructor Details
#initialize(covered:, missed:, omitted: 0, total_strength: 0.0, percent: nil) ⇒ CoverageStatistics
percent: overrides the computed percentage (used to report 0%
for tracked-but-never-loaded files).
39 40 41 42 43 44 45 46 |
# File 'lib/simplecov/coverage_statistics.rb', line 39 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 |
Instance Attribute Details
#covered ⇒ Integer (readonly)
Returns the value of attribute covered.
15 16 17 |
# File 'lib/simplecov/coverage_statistics.rb', line 15 def covered @covered end |
#missed ⇒ Integer (readonly)
Returns the value of attribute missed.
15 16 17 |
# File 'lib/simplecov/coverage_statistics.rb', line 15 def missed @missed end |
#omitted ⇒ Integer (readonly)
Returns the value of attribute omitted.
15 16 17 |
# File 'lib/simplecov/coverage_statistics.rb', line 15 def omitted @omitted end |
#percent ⇒ Float (readonly)
Returns the value of attribute percent.
15 16 17 |
# File 'lib/simplecov/coverage_statistics.rb', line 15 def percent @percent end |
#strength ⇒ Float (readonly)
Returns the value of attribute strength.
15 16 17 |
# File 'lib/simplecov/coverage_statistics.rb', line 15 def strength @strength end |
#total ⇒ Integer (readonly)
Returns the value of attribute total.
15 16 17 |
# File 'lib/simplecov/coverage_statistics.rb', line 15 def total @total end |
Class Method Details
.from(coverage_statistics) ⇒ CoverageStatistics
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/simplecov/coverage_statistics.rb', line 20 def self.from(coverage_statistics) sum_covered, sum_missed, sum_omitted, sum_total_strength = coverage_statistics.reduce(ZERO_STATS) 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 |
Instance Method Details
#compute_percent(covered, missed, total) ⇒ Float
50 51 52 53 54 |
# File 'lib/simplecov/coverage_statistics.rb', line 50 def compute_percent(covered, missed, total) return 100.0 if missed.zero? covered * 100.0 / total end |
#compute_strength(total_strength, total) ⇒ Float
56 57 58 59 60 |
# File 'lib/simplecov/coverage_statistics.rb', line 56 def compute_strength(total_strength, total) return 0.0 if total.zero? total_strength.to_f / total end |