diff --git a/README.md b/README.md index e715af5..b482a34 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # CI MPM Toy repo with some simple functions for the CI lecture + +trivial change 2 \ No newline at end of file diff --git a/simple_functions/functions1.py b/simple_functions/functions1.py index 8c63a4d..a52c322 100644 --- a/simple_functions/functions1.py +++ b/simple_functions/functions1.py @@ -1,5 +1,6 @@ +from functools import cache -__all__ = ['my_sum'] +__all__ = ['my_sum', 'factorial'] def my_sum(iterable): @@ -7,3 +8,7 @@ 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..acb9fc7 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,14 @@ 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 \ No newline at end of file