-
Notifications
You must be signed in to change notification settings - Fork 76
Fix float precision issue in coverage diff #533
Conversation
Codecov Report
@@ Coverage Diff @@
## master #533 +/- ##
============================================
+ Coverage 72.74% 72.80% +0.05%
- Complexity 1026 1028 +2
============================================
Files 88 88
Lines 3823 3824 +1
Branches 440 440
============================================
+ Hits 2781 2784 +3
+ Misses 894 893 -1
+ Partials 148 147 -1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
//Converting float point to Big decimal and converting back fixes the float precision point problem | ||
float diff = BigDecimal.valueOf((buildRatio.getPercentageFloat() - referenceRatio.getPercentageFloat())).floatValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you wrap that code into a method? Then you can write a small unit test that verifies the new behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests. Please re-review
6daf1cc
to
9b8e885
Compare
plugin/src/main/java/io/jenkins/plugins/coverage/CoverageProcessor.java
Outdated
Show resolved
Hide resolved
plugin/src/main/java/io/jenkins/plugins/coverage/CoverageProcessor.java
Outdated
Show resolved
Hide resolved
@uhafner What should be the next steps? Should I do something else for this to be merged and releases in new verison? |
No, I just needed to wait for Jenkins to mark this PR as green. Since this code is deprecated anyway there is no need to fix styling issues (I already removed the corresponding checks). |
While calculating difference in coverage, there might be a difference even without code change, due to floating point rounding errors. Converting the diff float to BigDecimal with appropriate scale and converting back solves this issue.
Fixes: https://github.com/jenkinsci/code-coverage-api-plugin/issues/191