Fix doubled negative sign in fractional() for negative mixed numbers#326
Open
patchwright wants to merge 1 commit into
Open
Fix doubled negative sign in fractional() for negative mixed numbers#326patchwright wants to merge 1 commit into
patchwright wants to merge 1 commit into
Conversation
fractional(-1.3) returned '-1 -3/10' instead of '-1 3/10', and fractional(-2.5) returned '-2 -1/2'. The whole-number part already carries the sign (int(-1.3) == -1), so the numerator should not repeat it. This was inconsistent with the pure-fraction case, which is already correct (fractional(-0.3) == '-3/10'). Use abs(numerator) in the mixed-fraction output. Add regression cases (-0.3, -1.3, -2.5) to the parametrized test_fractional, which previously had no negative inputs.
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.
Changes proposed in this pull request:
fractional()produced a doubled negative sign for negative mixed numbers.fractional(-1.3)returned'-1 -3/10'instead of'-1 3/10', andfractional(-2.5)returned'-2 -1/2'. The whole-number part already carries the sign (int(-1.3) == -1), so repeating it on the numerator is wrong. This is inconsistent with the pure-fraction case, which is already correct (fractional(-0.3) == '-3/10').abs(numerator)in the mixed-fraction output. Positives and pure fractions are unaffected.-0.3,-1.3,-2.5) to the parametrizedtest_fractional— it previously had no negative inputs. Verified the new cases fail on the current code and pass with the fix; the fulltests/test_number.pysuite (222 tests) passes andruffis clean.No existing issue.