diff --git a/lib/simplecov/file_list.rb b/lib/simplecov/file_list.rb index 21b3d75c..d5b9609c 100644 --- a/lib/simplecov/file_list.rb +++ b/lib/simplecov/file_list.rb @@ -31,14 +31,16 @@ def lines_of_code end # Computes the coverage based upon lines covered and lines missed + # @return [Float] def covered_percent return 100.0 if empty? or lines_of_code == 0 - covered_lines * 100.0 / lines_of_code + Float(covered_lines * 100.0 / lines_of_code) end # Computes the strength (hits / line) based upon lines covered and lines missed + # @return [Float] def covered_strength - return 0 if empty? or lines_of_code == 0 - map {|f| f.covered_strength }.inject(&:+).to_f / size + return 0.0 if empty? or lines_of_code == 0 + Float(map {|f| f.covered_strength }.inject(&:+).to_f / size) end end diff --git a/lib/simplecov/result.rb b/lib/simplecov/result.rb index 55268100..4f1a36de 100644 --- a/lib/simplecov/result.rb +++ b/lib/simplecov/result.rb @@ -47,7 +47,7 @@ def groups # The overall percentual coverage for this result def covered_percent # Make sure that weird rounding error from #15, #23 and #24 does not occur again! - total_lines.zero? ? 0 : 100.0 * covered_lines / total_lines + total_lines.zero? ? 0 : Float(100.0 * covered_lines / total_lines) end # The multiple of coverage for this result @@ -62,7 +62,7 @@ def covered_strength end end end - @covered_strength = m.to_f / total_lines + @covered_strength = Float(m.to_f / total_lines) end # Returns the count of lines that are covered diff --git a/lib/simplecov/source_file.rb b/lib/simplecov/source_file.rb index 9e578098..e091e2a7 100644 --- a/lib/simplecov/source_file.rb +++ b/lib/simplecov/source_file.rb @@ -111,24 +111,24 @@ def covered_percent return 100.0 if lines.length == 0 or lines.length == never_lines.count relevant_lines = lines.count - never_lines.count - skipped_lines.count if relevant_lines == 0 - 0 + 0.0 else - (covered_lines.count) * 100.0 / relevant_lines.to_f + Float((covered_lines.count) * 100.0 / relevant_lines.to_f) end end def covered_strength - return 0 if lines.length == 0 or lines.length == never_lines.count + return 0.0 if lines.length == 0 or lines.length == never_lines.count lines_strength = 0 lines.each do |c| lines_strength += c.coverage if c.coverage end - effective_lines_count = (lines.count - never_lines.count - skipped_lines.count).to_f + effective_lines_count = Float(lines.count - never_lines.count - skipped_lines.count) if effective_lines_count == 0 - 0 + 0.0 else strength = lines_strength / effective_lines_count round_float(strength, 1) @@ -178,9 +178,10 @@ def process_skipped_lines! private # ruby 1.9 could use Float#round(places) instead + # @return [Float] def round_float(float, places) - factor = (10 * places).to_f - (float * factor).round / factor + factor = Float(10 * places) + Float((float * factor).round / factor) end end end