Files
Python/maths/test_factorial.py
Md Mahiuddin e2a78d4e76
Some checks failed
directory_writer / directory_writer (push) Has been cancelled
ruff / ruff (push) Has been cancelled
sphinx / build_docs (push) Has been cancelled
sphinx / deploy_docs (push) Has been cancelled
Project Euler / project-euler (push) Has been cancelled
Project Euler / validate-solutions (push) Has been cancelled
build / build (push) Has been cancelled
Add test for non-integer input to factorial function (#13024)
* Add test for non-integer input to factorial function

* Update test_factorial.py

---------

Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
2025-10-20 03:59:36 +03:00

44 lines
1022 B
Python

# /// 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)
@pytest.mark.parametrize("function", [factorial, factorial_recursive])
def test_float_number(function):
with pytest.raises(ValueError):
function(1.5)
if __name__ == "__main__":
pytest.main(["-v", __file__])