-
-
Notifications
You must be signed in to change notification settings - Fork 29
fix: use big.Rat for precise calculation #504
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
Conversation
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.
Pull Request Overview
This PR aims to enhance the accuracy of coverage, code-to-test ratio, and test execution time computations by switching from float64 to arbitrary-precision *big.Rat calculations. Key changes include:
- Replacing float64 values with *big.Rat in evaluation functions.
- Updating test cases to support both float64 and *big.Rat inputs.
- Introducing pre-calculated *big.Rat edge-case values and adjusting error messages accordingly.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
config/config_test.go | Revised test cases to convert float64 to *big.Rat and added new tests leveraging big.Rat values. |
config/config.go | Updated functions to use *big.Rat instead of float64, including conversion logic for error messages. |
Comments suppressed due to low confidence (1)
config/config.go:365
- Verify that converting currentF to an int64 when creating a time.Duration does not cause unintended precision loss; consider adding a comment to document that this conversion is acceptable for error messaging.
return fmt.Errorf("test execution time is %v. the condition in the `testExecutionTime.acceptable:` section is not met (`%s`)", time.Duration(int64(currentF)), org)
covRat = big.NewRat(int64(tt.cov*10000), 10000) | ||
prevRat = big.NewRat(int64(tt.prev*10000), 10000) |
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.
Consider extracting the repeated conversion logic from float64 to *big.Rat into a helper function to reduce duplication across the test cases.
covRat = big.NewRat(int64(tt.cov*10000), 10000) | |
prevRat = big.NewRat(int64(tt.prev*10000), 10000) | |
covRat = float64ToBigRat(tt.cov) | |
prevRat = float64ToBigRat(tt.prev) |
Copilot uses AI. Check for mistakes.
diffF, _ := diff.Float64() | ||
currentF, _ := current.Float64() | ||
prevF, _ := prev.Float64() |
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.
The conversion of *big.Rat values to float64 for use in expression evaluation is repeated; consider abstracting this conversion into a helper function to improve readability and reduce duplication.
diffF, _ := diff.Float64() | |
currentF, _ := current.Float64() | |
prevF, _ := prev.Float64() | |
diffF := ratToFloat64(diff) | |
currentF := ratToFloat64(current) | |
prevF := ratToFloat64(prev) |
Copilot uses AI. Check for mistakes.
Code Metrics Report
Details | | main (ca82aca) | #504 (8658084) | +/- |
|---------------------|----------------|----------------|-------|
+ | Coverage | 50.3% | 50.4% | +0.1% |
| Files | 53 | 53 | 0 |
| Lines | 3825 | 3841 | +16 |
+ | Covered | 1925 | 1938 | +13 |
+ | Code to Test Ratio | 1:0.5 | 1:0.5 | +0.0 |
| Code | 7494 | 7511 | +17 |
+ | Test | 4415 | 4475 | +60 |
| Test Execution Time | 30s | 30s | 0s | Code coverage of files in pull request scope (61.8% → 63.4%)
Benchmark-0 (this is custom metrics test)
Benchmark-1 (this is custom metrics test)
Reported by octocov |
Fix: #503
Summary
This pull request introduces significant changes to improve precision in calculations for coverage, code-to-test ratio, and test execution time by replacing
float64
with*big.Rat
(arbitrary-precision rational numbers). It also updates the corresponding test cases to accommodate the new precision-based logic. Below is a summary of the most important changes:Precision Improvements in Calculations:
float64
with*big.Rat
for calculations: Updated functionscoverageAcceptable
,codeToTestRatioAcceptable
, andtestExecutionTimeAcceptable
to use*big.Rat
instead offloat64
for improved precision in comparisons and calculations. (config/config.go
, [1] [2] [3] [4]big.Rat
operations: Added logic to compute differences and convert*big.Rat
values tofloat64
for compatibility in error messages and expressions. (config/config.go
, [1] [2] [3]Test Enhancements:
*big.Rat
: Modified test cases for coverage, code-to-test ratio, and test execution time to include bothfloat64
and*big.Rat
inputs, ensuring precision-sensitive scenarios are tested. (config/config_test.go
, [1] [2] [3]big.Rat
values for edge cases: Introduced specialbig.Rat
values (e.g.,almostSixty
,oneThirdPlusSmall
,almostOneMinute
) to test scenarios that cannot be represented accurately withfloat64
. (config/config_test.go
, [1] [2] [3]Code Maintenance:
math/big
: Added themath/big
package to support arbitrary-precision rational number operations. (config/config.go
, [1];config/config_test.go
, [2]These changes ensure greater accuracy in calculations and robustness in handling edge cases, particularly for conditions that require high precision.