mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-12 17:49:50 +00:00
Improved test coverage in decimal_to_fraction.py (#12608)
* Imporved test coverage in decimal_to_fraction.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update decimal_to_fraction.py * Update decimal_to_fraction.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
parent
a415a953c3
commit
4fbd350b6e
@ -16,6 +16,20 @@ def decimal_to_fraction(decimal: float | str) -> tuple[int, int]:
|
|||||||
>>> decimal_to_fraction("78td")
|
>>> decimal_to_fraction("78td")
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
ValueError: Please enter a valid number
|
ValueError: Please enter a valid number
|
||||||
|
>>> decimal_to_fraction(0)
|
||||||
|
(0, 1)
|
||||||
|
>>> decimal_to_fraction(-2.5)
|
||||||
|
(-5, 2)
|
||||||
|
>>> decimal_to_fraction(0.125)
|
||||||
|
(1, 8)
|
||||||
|
>>> decimal_to_fraction(1000000.25)
|
||||||
|
(4000001, 4)
|
||||||
|
>>> decimal_to_fraction(1.3333)
|
||||||
|
(13333, 10000)
|
||||||
|
>>> decimal_to_fraction("1.23e2")
|
||||||
|
(123, 1)
|
||||||
|
>>> decimal_to_fraction("0.500")
|
||||||
|
(1, 2)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
decimal = float(decimal)
|
decimal = float(decimal)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user