diff --git a/README.md b/README.md index e715af5..0d8176d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # CI MPM Toy repo with some simple functions for the CI lecture + +hi diff --git a/simple_functions/functions1.py b/simple_functions/functions1.py index 8c63a4d..eae5287 100644 --- a/simple_functions/functions1.py +++ b/simple_functions/functions1.py @@ -1,5 +1,7 @@ -__all__ = ['my_sum'] +from functools import cache + +__all__ = ['my_sum', 'factorial'] def my_sum(iterable): @@ -7,3 +9,8 @@ def my_sum(iterable): for i in iterable: tot += i return tot + + +@cache +def factorial(n): + return n * factorial(n-1) if n else 1 diff --git a/tests/test_simple_functions.py b/tests/test_simple_functions.py index 5a03b52..1f4494f 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