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