Repository commit
c0db072 (master)
Python version (python --version)
Python 3.12.13
Dependencies version (pip freeze)
Standard library only (math).
Expected behavior
The docstring of maths.largest_of_very_large_numbers.res documents the following doctest for a negative x:
>>> res(-1, 5)
Traceback (most recent call last):
...
ValueError: expected a positive input
So res(-1, 5) should raise ValueError with the message expected a positive input, and this doctest should pass under pytest --doctest-modules.
Actual behavior
There is no input validation in res(). When x < 0 and y != 0 the function reaches math.log10(x), which raises ValueError: math domain error (wrong message) instead of the documented expected a positive input. The doctest as written therefore fails:
$ python3 -m doctest maths/largest_of_very_large_numbers.py -v
...
Failed example:
res(-1, 5)
Expected:
Traceback (most recent call last):
...
ValueError: expected a positive input
Got:
Traceback (most recent call last):
...
return y * math.log10(x)
^^^^^^^^^^^^^
ValueError: math domain error
1 items had failures:
1 of 4 in maths.largest_of_very_large_numbers.res
***Test Failed*** 1 failures.
Suggested fix
Add the missing check at the top of res():
if x < 0:
raise ValueError("expected a positive input")
This makes the code match the documented contract, and turns the currently-failing doctest into a passing one. A PR is being opened.
Repository commit
c0db072 (master)
Python version (python --version)
Python 3.12.13
Dependencies version (pip freeze)
Standard library only (
math).Expected behavior
The docstring of
maths.largest_of_very_large_numbers.resdocuments the following doctest for a negativex:So
res(-1, 5)should raiseValueErrorwith the messageexpected a positive input, and this doctest should pass underpytest --doctest-modules.Actual behavior
There is no input validation in
res(). Whenx < 0andy != 0the function reachesmath.log10(x), which raisesValueError: math domain error(wrong message) instead of the documentedexpected a positive input. The doctest as written therefore fails:Suggested fix
Add the missing check at the top of
res():This makes the code match the documented contract, and turns the currently-failing doctest into a passing one. A PR is being opened.