diff --git a/src/math_utils.py b/src/math_utils.py index e52f339..aca1dad 100644 --- a/src/math_utils.py +++ b/src/math_utils.py @@ -1,11 +1,11 @@ -""" -Math utility functions -""" - -def add(a, b): - """Add two numbers""" - return a + b - -def multiply(a, b): - """Multiply two numbers""" - return a * b +def fibonacci(n): + if n < 0: + raise ValueError("n must be non-negative") + if n == 0: + return 0 + if n == 1: + return 1 + a, b = 0, 1 + for _ in range(2, n + 1): + a, b = b, a + b + return b diff --git a/tests/test_math_utils.py b/tests/test_math_utils.py index 516f210..a16091f 100644 --- a/tests/test_math_utils.py +++ b/tests/test_math_utils.py @@ -1,15 +1,25 @@ -import sys -from pathlib import Path -sys.path.insert(0, str(Path(__file__).parent.parent / 'src')) +import pytest +from src.math_utils import fibonacci -from math_utils import add, multiply -def test_add(): - assert add(2, 3) == 5 - assert add(-1, 1) == 0 - assert add(0, 0) == 0 +def test_fibonacci_base_cases(): + assert fibonacci(0) == 0 + assert fibonacci(1) == 1 -def test_multiply(): - assert multiply(2, 3) == 6 - assert multiply(-1, 5) == -5 - assert multiply(0, 10) == 0 + +def test_fibonacci_small_values(): + assert fibonacci(2) == 1 + assert fibonacci(3) == 2 + assert fibonacci(4) == 3 + assert fibonacci(5) == 5 + assert fibonacci(10) == 55 + + +def test_fibonacci_negative_raises(): + with pytest.raises(ValueError) as excinfo: + fibonacci(-1) + assert str(excinfo.value) == "n must be non-negative" + + +def test_fibonacci_large_value(): + assert fibonacci(20) == 6765