|
1 | | -import unittest |
2 | | -from factorial import factorial |
| 1 | +# /// script |
| 2 | +# requires-python = ">=3.13" |
| 3 | +# dependencies = [ |
| 4 | +# "pytest", |
| 5 | +# ] |
| 6 | +# /// |
3 | 7 |
|
| 8 | +import pytest |
4 | 9 |
|
5 | | -class TestFactorial(unittest.TestCase): |
6 | | - def test_zero(self): |
7 | | - self.assertEqual(factorial(0), 1) |
| 10 | +from maths.factorial import factorial, factorial_recursive |
8 | 11 |
|
9 | | - def test_positive_integers(self): |
10 | | - self.assertEqual(factorial(1), 1) |
11 | | - self.assertEqual(factorial(5), 120) |
12 | | - self.assertEqual(factorial(7), 5040) |
13 | 12 |
|
14 | | - def test_large_number(self): |
15 | | - self.assertEqual(factorial(10), 3628800) |
| 13 | +@pytest.mark.parametrize("function", [factorial, factorial_recursive]) |
| 14 | +def test_zero(function): |
| 15 | + assert function(0) == 1 |
16 | 16 |
|
17 | | - def test_negative_number(self): |
18 | | - with self.assertRaises(ValueError): |
19 | | - factorial(-3) |
| 17 | + |
| 18 | +@pytest.mark.parametrize("function", [factorial, factorial_recursive]) |
| 19 | +def test_positive_integers(function): |
| 20 | + assert function(1) == 1 |
| 21 | + assert function(5) == 120 |
| 22 | + assert function(7) == 5040 |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.parametrize("function", [factorial, factorial_recursive]) |
| 26 | +def test_large_number(function): |
| 27 | + assert function(10) == 3628800 |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.parametrize("function", [factorial, factorial_recursive]) |
| 31 | +def test_negative_number(function): |
| 32 | + with pytest.raises(ValueError): |
| 33 | + function(-3) |
20 | 34 |
|
21 | 35 |
|
22 | 36 | if __name__ == "__main__": |
23 | | - unittest.main() |
| 37 | + pytest.main(["-v", __file__]) |
0 commit comments