Skip to content

Commit

Permalink
Merge pull request #128 from japgolly/nan_fix
Browse files Browse the repository at this point in the history
Prevent divisions by zero
  • Loading branch information
colszowka committed May 10, 2012
2 parents fc62877 + da9358a commit 8322eef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/simplecov/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def covered_percent

# The multiple of coverage for this result
def covered_strength
return 0 if total_lines.zero?
return @covered_strength if @covered_strength
m = 0
@files.each do |file|
Expand Down
5 changes: 4 additions & 1 deletion lib/simplecov/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def line(number)
# The coverage for this file in percent. 0 if the file has no relevant lines
def covered_percent
return 100.0 if lines.length == 0 or lines.length == never_lines.count
(covered_lines.count) * 100 / (lines.count - never_lines.count - skipped_lines.count).to_f
relevant_lines = lines.count - never_lines.count - skipped_lines.count
return 0 if relevant_lines == 0
(covered_lines.count) * 100 / relevant_lines.to_f
end

def covered_strength
Expand All @@ -119,6 +121,7 @@ def covered_strength
lines_strength += c.coverage if c.coverage
end
effective_lines_count = (lines.count - never_lines.count - skipped_lines.count).to_f
return 0 if effective_lines_count == 0
strength = lines_strength / effective_lines_count
round_float(strength, 1)
end
Expand Down

0 comments on commit 8322eef

Please sign in to comment.