8000 Add unit tests for factorial.py by QasimUmarKhan · Pull Request #12815 · TheAlgorithms/Python · GitHub
[go: up one dir, main page]

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 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add unit tests for factorial.py
  • Loading branch information
QasimUmarKhan committed Jul 1, 2025
commit f5b32a10a81bc25f0e418c6d572914f86323a287
22 changes: 22 additions & 0 deletions maths/test_factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest
from factorial import factorial

class TestFactorial(unittest.TestCase):

def test_zero(self):
self.assertEqual(factorial(0), 1)

def test_positive_integers(self):
self.assertEqual(factorial(1), 1)
self.assertEqual(factorial(5), 120)
self.assertEqual(factorial(7), 5040)

def test_large_number(self):
self.assertEqual(factorial(10), 3628800)

def test_negative_number(self):
with self.assertRaises(ValueError):
factorial(-3)

if __name__ == '__main__':
unittest.main()
Loading
0