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

Always round numbers down, never up #146

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bquorning
Copy link

When the coverage percentage is rounded up, people may end up misconfiguring SimpleCov with a number that 0.01 too high. They may even think they have a 100% converage, when in fact the coverage is only marginally higher than 99.995%.

This commit changes all uses of #round for #floor, thus always rounding down and never up.

Fixes #130.
May even fix simplecov-ruby/simplecov#948 too.

@bquorning
Copy link
Author

cc @amatsuda

@amatsuda
Copy link
Member

@bquorning Could you add a regression test that reproduces the issue? Thanks!

@bquorning bquorning force-pushed the use-floor-not-round branch 4 times, most recently from 4f6da24 to 6dbf7be Compare February 14, 2025 09:53
Also, consistently render percentages without a space before it.

To get some usable data for the test, I copied a number of files from
SingleCov's spec/source_file_spec.rb.
@bquorning bquorning force-pushed the use-floor-not-round branch 2 times, most recently from 759c8c6 to 0dd053c Compare February 14, 2025 10:59
When the coverage percentage is rounded up, people may end up
misconfiguring SimpleCov with a number that 0.01 too high. They may even
think they have a 100% converage, when in fact the coverage is only
marginally higher than 99.995%.

This commit changes all uses of `#round` for  `#floor`, thus always
rounding _down_ and never _up_.
I don't think it matters if it's rounded up or down. The point here is
that we render it the same way in the header as we do in the table.
@bquorning
Copy link
Author

I didn’t find any existing tests in the repo, so I copied a handful of files from simplecov's spec suite to generate some usable coverage numbers to output. The test is currently very long and hard to read, but I’m ready to iterate on that.

What is more concerning is that the tests are currently failing on Ruby 2.4 and 2.5. @amatsuda do you know if simplecov-html actually works with those Ruby versions and simplecov v0.18.5?

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