From 77a4b9b2dc85b39f3f09df5a4640e6fc1edf775e Mon Sep 17 00:00:00 2001 From: acse-lb1223 Date: Tue, 17 Oct 2023 11:04:31 +0100 Subject: [PATCH 1/3] trivial change --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e715af5..42e4e01 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. \ No newline at end of file From b11dd96d8e087a4f31cf426393e2f504fd79fc46 Mon Sep 17 00:00:00 2001 From: acse-lb1223 Date: Tue, 17 Oct 2023 11:05:58 +0100 Subject: [PATCH 2/3] trivial change 2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42e4e01..c820c7b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # CI MPM Toy repo with some simple functions for the CI lecture -Trivial change. \ No newline at end of file +Trivial change. 2. \ No newline at end of file From 64f03a80f98f4e0e64683b00f4bbbca0c135cb75 Mon Sep 17 00:00:00 2001 From: acse-lb1223 Date: Tue, 17 Oct 2023 11:17:00 +0100 Subject: [PATCH 3/3] Add factorial function --- simple_functions/functions1.py | 7 ++++++- tests/test_simple_functions.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/simple_functions/functions1.py b/simple_functions/functions1.py index 8c63a4d..e591fc6 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 \ No newline at end of file diff --git a/tests/test_simple_functions.py b/tests/test_simple_functions.py index 5a03b52..1b3a87f 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 \ No newline at end of file