Skip to content

Add unit tests for factorial.py #12815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 5, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions maths/test_factorial.py
Original file line number Diff line number Diff line change
@@ -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__])
Loading