fix: report non-zero megabyte size for xkcd-kb unit in non-leap years - #740
Merged
Merged
Conversation
The xkcd-kb size case assigned `size` only inside the leap-year branch with no else, so in a non-leap year `size` stayed 0.0 and the output read "0.000 megabytes" for any byte count, contradicting the unit's help text "1000 bytes during leap years, 1024 otherwise". Divide by a new pure helper xkcdKbDivisor(year) returning 1_000_000 (1000-based) in leap years and 1_048_576 (1024-based) otherwise, mirroring the existing pure isLeapYear(year). Adds TestCalculateSizeXkcdKb covering both year classes. I licence this contribution under the MIT licence.
Owner
|
Cheers. Should make it to the next release which should be soon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
xkcd-kbsize case assignedsizeonly inside the leap-year branch with noelse, so in a non-leap yearsizestayed0.0andsccprinted0.000 megabytes (XKCD-KB)for every file — in 3 of every 4 years. This contradicts the unit's own help text "1000 bytes during leap years, 1024 otherwise" (which says non-leap must be 1024-based = 1,048,576). Reproduced on master: 3,000,001-byte file, year 2026 → "0.000 megabytes". Every other--size-unitemits a real figure.Fix
Divide by a new pure helper
xkcdKbDivisor(year)returning1_000_000(1000-based) in a leap year and1_048_576(1024-based) otherwise — mirroring the existing pureisLeapYear(year). Nolanguages.jsonchange, so nogo generatedrift.Test plan
go test -race ./processor/...— green, including a newTestCalculateSizeXkcdKbthat asserts the output is non-zero in a non-leap year and matches10_000_000/(1024*1024) = 9.537 megabytes, plus year-independent assertionsxkcdKbDivisor(2026) == 1_048_576andxkcdKbDivisor(2024) == 1_000_000.I licence this contribution under the MIT licence.