Repository navigation
R23-T024: Input contract enforcement and boundary doctests for base_neg2_conversion - #115
Open
mohammedsohail0301-dot wants to merge 1 commit into
Open
mohammedsohail0301-dot wants to merge 1 commit into
mohammedsohail0301-dot wants to merge 1 commit into
Conversation
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.
Describe your change
Checklist
Description
This pull request completes Task R23-T024: establishing a strict input contract and robust exception handling for
decimal_to_negative_base_2inmaths/base_neg2_conversion.py.Prior to this change:
True/False) were silently treated as integers, returning1and0.3.5,-2.5) caused internal string accumulator crashes (ValueError: invalid literal for int() with base 10: '1.01.01.5'), and0.0silently bypassed type checks.str,None, collections) triggered unhandled internaldivmodTypeErrors.We added an upfront type guard raising
TypeError: num must be an integer, not <type>, added 5 new doctests covering floats, bools, strings, None, and huge ints, and preserved all 4 original doctests (0,-19,4,7).Type of Change
Input Probing Analysis (Old vs. New Behavior)
True1(returned value)TypeError: num must be an integer, not boolFalse0(returned value)TypeError: num must be an integer, not bool3.5ValueError: invalid literal for int() with base 10: '1.01.01.5'TypeError: num must be an integer, not float0.00(returned value)TypeError: num must be an integer, not float-2.5ValueError: invalid literal for int() with base 10: '1.01.0-0.01.5'TypeError: num must be an integer, not float'10'TypeError: unsupported operand type(s) for divmod(): 'str' and 'int'TypeError: num must be an integer, not str''TypeError: unsupported operand type(s) for divmod(): 'str' and 'int'TypeError: num must be an integer, not str'###'TypeError: unsupported operand type(s) for divmod(): 'str' and 'int'TypeError: num must be an integer, not strNoneTypeError: unsupported operand type(s) for divmod(): 'NoneType' and 'int'TypeError: num must be an integer, not NoneType[1, 2]TypeError: unsupported operand type(s) for divmod(): 'list' and 'int'TypeError: num must be an integer, not list(1+2j)TypeError: unsupported operand type(s) for divmod(): 'complex' and 'int'TypeError: num must be an integer, not complex10**1810010001000011100101111110100111110001010010000000000000000001001000100001110010111111010011111000101001000000000000000000-19111101111101000Changes Made
maths/base_neg2_conversion.py:if isinstance(num, bool) or not isinstance(num, int): raise TypeError(...).Raises: TypeErrorsection in docstring.3.5), bool (True), string ("10"), None (None), and huge int (10**18).0,-19,4,7) preserved and passing.work/R23-T024/:probe_inputs.py: Automated testing script comparing old vs. new behavior across 14 inputs.FINDINGS.md: Complete theoretical explanation, failure mode root causes, and verification details.test_output.txt: Test execution logs for doctests, pytest, ruff, and ty check.Testing & Verification
python3 -m doctest -v maths/base_neg2_conversion.py-> 9/9 doctests passed.uv run --with pytest pytest --doctest-modules maths/base_neg2_conversion.py-> 1 passed in 0.02s.uvx ruff check maths/base_neg2_conversion.py work/R23-T024/probe_inputs.py-> All checks passed.uvx ruff format --check maths/base_neg2_conversion.py work/R23-T024/probe_inputs.py-> 2 files already formatted.uvx ty check --exit-zero maths/base_neg2_conversion.py-> 0 diagnostics.Additional Notes
student/E26B07F0850/R23-T024-upstream(andR23-T024-upstream) containing only the changes inmaths/base_neg2_conversion.pyhas been created and pushed for a later upstream PR.