Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate total project cov according to line count for each target #203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/xcov/model/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ class Report < Xcov::Base

def initialize(targets)
@targets = targets
@coverage = average_coverage(targets)
@coverage = total_project_coverage(targets)
@displayable_coverage = self.create_displayable_coverage
@coverage_color = self.create_coverage_color
@summary = self.create_summary
end

def average_coverage targets
def total_project_coverage targets
return 0 if targets.count == 0
return targets.first.coverage if targets.count == 1

acc_coverage = targets.reduce(0) { |acc, target| acc + target.coverage }
acc_coverage.to_f / targets.count
acc_total_covered_lines = targets.reduce(0) { |acc, target| acc + target.total_covered_lines }
acc_total_executable_lines = targets.reduce(0) { |acc, target| acc + target.total_executable_lines }
acc_total_covered_lines.to_f / acc_total_executable_lines.to_f
end

def print_description
Expand Down
8 changes: 5 additions & 3 deletions lib/xcov/model/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ class Target < Xcov::Base
attr_accessor :name
attr_accessor :files
attr_accessor :file_templates
attr_accessor :total_covered_lines
attr_accessor :total_executable_lines

def initialize(name, files)
@name = CGI::escapeHTML(name)
@files = files
totalCoveredLines = files.reduce(0) { |acc, file| acc + file.coveredLines }
totalExecutableLines = files.reduce(0) { |acc, file| acc + file.executableLines }
@coverage = files.count == 0 || totalExecutableLines == 0 ? 0.0 : totalCoveredLines.to_f / totalExecutableLines.to_f
@total_covered_lines = files.reduce(0) { |acc, file| acc + file.coveredLines }
@total_executable_lines = files.reduce(0) { |acc, file| acc + file.executableLines }
@coverage = files.count == 0 || @total_executable_lines == 0 ? 0.0 : @total_covered_lines.to_f / @total_executable_lines.to_f
@displayable_coverage = self.create_displayable_coverage
@coverage_color = self.create_coverage_color
@id = Target.create_id(name)
Expand Down