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

All Files hits/lines value appears to be improperly weighted #179

Closed
tovodeverett opened this issue Dec 3, 2012 · 5 comments · Fixed by #192
Closed

All Files hits/lines value appears to be improperly weighted #179

tovodeverett opened this issue Dec 3, 2012 · 5 comments · Fixed by #192

Comments

@tovodeverett
Copy link

It appears that while the All Files %coverage value is properly calculated by summing the lines covered and dividing by the sum of the relevant lines, the All Files hits/line value is simply an average of the per-file Avg. Hits / Line value. If you have a file with very few relevant lines and high Avg. Hits / Line, this can result in a spurious value. A more accurate way of calculating this value would be to calculate the hits for each file by multiplying the per-file Avg. Hits / Line by the per-file Relevant Lines, summing those values, and then dividing by the sum of the relevant lines.

@c-lliope
Copy link
Contributor

Yeah, I noticed this as well. As an example, I have three controllers:

application_controller.rb
blogs_controller.rb
blog_entries_controller.rb

The application controller is empty except for the protect_from_forgery call, so it has 2 lines covered at 1 hit per line.
The other two controllers have 40 lines covered at an average of 4.8 hits/line.

The total says that the controllers are covered at 3.53 hits per line -- (4.8+4.8+1)/3 = 3.53

It should be (4.8 * 40 + 4.8 * 40 + 1.0 * 2)/(40+40+2) = 4.7 hits per line

@c-lliope
Copy link
Contributor

It looks like the problem is with the covered_strength method on line 40 of lib/simplecov/file_list.rb

I'll fork and fix it.

@c-lliope
Copy link
Contributor

Pull Request: #192

@colszowka
Copy link
Collaborator

Thanks @Graysonwright, this should be resolved now as part of the 0.8.0 release, which ships today.

@c-lliope
Copy link
Contributor

Awesome, thanks! Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants