Class: SimpleCov::CoverageStatistics
- Inherits:
-
Object
- Object
- SimpleCov::CoverageStatistics
- Defined in:
- lib/simplecov/coverage_statistics.rb,
sig/simplecov.rbs
Overview
One coverage criterion's numbers, uniform across criteria: total, covered, missed, omitted (only meaningful for line coverage), percent, and strength, the average hits per coverable unit, which the oneshot-lines format has no way to produce.
Constant Summary collapse
- ZERO_STATS =
: [Integer, Integer, Integer, Float]
[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
-
.from(coverage_statistics) ⇒ CoverageStatistics
Strength is remultiplied by loc because files have different strengths and line counts, giving them a different weight in the total.
Instance Method Summary collapse
- #compute_percent(covered, missed, total) ⇒ Float
- #compute_strength(total_strength, total) ⇒ Float
-
#initialize(covered:, missed:, omitted: 0, total_strength: 0, percent: nil) ⇒ CoverageStatistics
constructor
A new instance of CoverageStatistics.
Constructor Details
#initialize(covered:, missed:, omitted: 0, total_strength: 0, percent: nil) ⇒ CoverageStatistics
Returns a new instance of CoverageStatistics.
29 30 31 32 33 34 35 36 |
# File 'lib/simplecov/coverage_statistics.rb', line 29 def initialize(covered:, missed:, omitted: 0, total_strength: 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.
9 10 11 |
# File 'lib/simplecov/coverage_statistics.rb', line 9 def covered @covered end |
#missed ⇒ Integer (readonly)
Returns the value of attribute missed.
9 10 11 |
# File 'lib/simplecov/coverage_statistics.rb', line 9 def missed @missed end |
#omitted ⇒ Integer (readonly)
Returns the value of attribute omitted.
9 10 11 |
# File 'lib/simplecov/coverage_statistics.rb', line 9 def omitted @omitted end |
#percent ⇒ Float (readonly)
Returns the value of attribute percent.
9 10 11 |
# File 'lib/simplecov/coverage_statistics.rb', line 9 def percent @percent end |
#strength ⇒ Float (readonly)
Returns the value of attribute strength.
9 10 11 |
# File 'lib/simplecov/coverage_statistics.rb', line 9 def strength @strength end |
#total ⇒ Integer (readonly)
Returns the value of attribute total.
9 10 11 |
# File 'lib/simplecov/coverage_statistics.rb', line 9 def total @total end |
Class Method Details
.from(coverage_statistics) ⇒ CoverageStatistics
Strength is remultiplied by loc because files have different strengths and line counts, giving them a different weight in the total.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simplecov/coverage_statistics.rb', line 15 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, 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
40 41 42 43 44 |
# File 'lib/simplecov/coverage_statistics.rb', line 40 def compute_percent(covered, missed, total) return 100.0 if missed.zero? covered * 100.0 / total end |
#compute_strength(total_strength, total) ⇒ Float
46 47 48 49 50 |
# File 'lib/simplecov/coverage_statistics.rb', line 46 def compute_strength(total_strength, total) return 0.0 if total.zero? total_strength.fdiv(total) end |