diff --git a/simple_functions/functions1.py b/simple_functions/functions1.py index 8c63a4d..070774b 100644 --- a/simple_functions/functions1.py +++ b/simple_functions/functions1.py @@ -1,9 +1,13 @@ +from functools import cache +__all__ = ['my_sum', 'factorial'] -__all__ = ['my_sum'] - - +# ????? def my_sum(iterable): tot = 0 for i in iterable: tot += i return tot + +@cache +def factorial(n): + return n * factorial(n-1) if n else 1 \ No newline at end of file diff --git a/tests/test_simple_functions.py b/tests/test_simple_functions.py index 5a03b52..08ce7b8 100644 --- a/tests/test_simple_functions.py +++ b/tests/test_simple_functions.py @@ -1,6 +1,6 @@ import pytest -from simple_functions import my_sum +from simple_functions import my_sum, factorial class TestSimpleFunctions(object): @@ -14,3 +14,13 @@ def test_my_add(self, iterable, expected): '''Test our add function''' isum = my_sum(iterable) assert isum == expected + + @pytest.mark.parametrize('number, expected', [ + (5, 120), + (3, 6), + (1, 1) + ]) + def test_factorial(self, number, expected): + '''Test our factorial function''' + answer = factorial(number) + assert answer == expected