mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-07 11:37:36 +08:00
Add unit tests for factorial.py (#12815)
* Add unit tests for factorial.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * uvx --python=3.12 unittest2pytest --write test_factorial.py * Update error message in current_stock_price.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
37
maths/test_factorial.py
Normal file
37
maths/test_factorial.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# /// script
|
||||||
|
# requires-python = ">=3.13"
|
||||||
|
# dependencies = [
|
||||||
|
# "pytest",
|
||||||
|
# ]
|
||||||
|
# ///
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from maths.factorial import factorial, factorial_recursive
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("function", [factorial, factorial_recursive])
|
||||||
|
def test_zero(function):
|
||||||
|
assert function(0) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("function", [factorial, factorial_recursive])
|
||||||
|
def test_positive_integers(function):
|
||||||
|
assert function(1) == 1
|
||||||
|
assert function(5) == 120
|
||||||
|
assert function(7) == 5040
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("function", [factorial, factorial_recursive])
|
||||||
|
def test_large_number(function):
|
||||||
|
assert function(10) == 3628800
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("function", [factorial, factorial_recursive])
|
||||||
|
def test_negative_number(function):
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
function(-3)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
pytest.main(["-v", __file__])
|
@ -23,7 +23,7 @@ Current ORCL stock price is 188.87
|
|||||||
def stock_price(symbol: str = "AAPL") -> str:
|
def stock_price(symbol: str = "AAPL") -> str:
|
||||||
"""
|
"""
|
||||||
>>> stock_price("EEEE")
|
>>> stock_price("EEEE")
|
||||||
'- '
|
'No <fin-streamer> tag with the specified data-testid attribute found.'
|
||||||
>>> isinstance(float(stock_price("GOOG")),float)
|
>>> isinstance(float(stock_price("GOOG")),float)
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user