Skip to content

Commit 09cab7f

Browse files
committed
Enhanced test coverage with property-based, boundary, and type testing
1 parent 3688949 commit 09cab7f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/test_factorial.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
from hypothesis import given, strategies as st
3+
from factorial import factorial
4+
5+
# Original tests
6+
def test_factorial():
7+
assert factorial(5) == 120
8+
assert factorial(0) == 1
9+
assert factorial(3) == 6
10+
11+
def test_factorial_negative():
12+
with pytest.raises(ValueError):
13+
factorial(-5)
14+
15+
# Large number testing
16+
def test_factorial_large_numbers():
17+
assert factorial(10) == 3628800
18+
assert factorial(20) == 2432902008176640000
19+
20+
# Property-based testing
21+
@given(st.integers(min_value=0, max_value=20))
22+
def test_factorial_properties(n):
23+
result = factorial(n)
24+
if n > 0:
25+
assert result == n * factorial(n-1)
26+
else:
27+
assert result == 1
28+
29+
# Boundary testing
30+
def test_factorial_boundary():
31+
assert factorial(1) == 1
32+
with pytest.raises(ValueError):
33+
factorial(1000) # Test upper limit
34+
35+
# Type checking
36+
def test_factorial_type_validation():
37+
with pytest.raises(TypeError):
38+
factorial(3.14)
39+
with pytest.raises(TypeError):
40+
factorial("5")

0 commit comments

Comments
 (0)