-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use CoverageData everywhere for consistency
This allows us to get rid off duplicated and inconsistent calculations. As a side effect of this, #565 is fixed now. So, fixes #565. The bigger purpose is multi step though where the access to coverage data is normalized and hence methods that work with expecting a minimum amount of coverage and formatters can work with the known good same data base as opposed to memoizing all different method names. At first I wanted to only do it for FileList and leave the rest for later. But the strength computation needed the total number of lines of code and so to pass it in I'd have had to calculate it but I wanted to calculate it only in CoverageData and there the avalanche started.... Commit also includes moving methods around in SourceFile to be private - it happened in the moment, forgive me for no extra commit (it was hard to determine what I could delete/what I need to adjust etc.).
- Loading branch information
Showing
4 changed files
with
174 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,21 +13,44 @@ module SimpleCov | |
class CoverageData | ||
attr_reader :total, :covered, :missed, :strength, :percent | ||
|
||
def self.from(coverage_data) | ||
covered, missed, total_strength = | ||
coverage_data.reduce([0, 0, 0.0]) do |(covered, missed, total_strength), file_coverage_data| | ||
[ | ||
covered + file_coverage_data.covered, | ||
missed + file_coverage_data.missed, | ||
# gotta remultiply with loc because files have different strenght and loc | ||
# giving them a different "weight" in total | ||
total_strength + (file_coverage_data.strength * file_coverage_data.total) | ||
] | ||
end | ||
|
||
new(covered: covered, missed: missed, total_strength: total_strength) | ||
end | ||
|
||
# Requires only covered, missed and strength to be initialized. | ||
# | ||
# Other values are computed by this class. | ||
def initialize(covered:, missed:, strength: nil) | ||
def initialize(covered:, missed:, total_strength: 0.0) | ||
@covered = covered | ||
@missed = missed | ||
@strength = strength | ||
@total = covered + missed | ||
@percent = compute_percent(covered, total) | ||
@strength = compute_strength(total_strength, @total) | ||
end | ||
|
||
private | ||
|
||
def compute_percent(covered, total) | ||
return 100.0 if total.zero? | ||
|
||
Float(covered * 100.0 / total) | ||
end | ||
|
||
def compute_strength(total_strength, total) | ||
return 0.0 if total.zero? | ||
|
||
Float(total_strength.to_f / total) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
PragTob
Author
Collaborator
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
float divided will always return a float no need to cast?