From 9346b1a382567e7d482093e93f938c1f30c0202d Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 29 Aug 2023 12:03:17 +0300 Subject: [PATCH 1/3] add population test case --- logistic.py | 2 ++ test_logistic.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/logistic.py b/logistic.py index e49d1c2..fa3f9b5 100644 --- a/logistic.py +++ b/logistic.py @@ -1 +1,3 @@ # Your code goes here +def f(x,r): + return r * x * (1-x) \ No newline at end of file diff --git a/test_logistic.py b/test_logistic.py index 9391bee..e81e191 100644 --- a/test_logistic.py +++ b/test_logistic.py @@ -14,3 +14,13 @@ def test_f_corner_cases(): for x, r, expected in cases: result = f(x, r) assert_allclose(result, expected) + +def test_generic_cases(): + cases = [ + (0.1,2.2,0.198), + (0.2,3.4,0.544), + (0.5,2,0.5) + ] + for x, r, expected in cases: + result = f(x, r) + assert_allclose(result, expected) \ No newline at end of file From 34b46a642611c660969aaf2fd9f7358ed288c6d4 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 29 Aug 2023 12:30:08 +0300 Subject: [PATCH 2/3] Use decorator for testing multiple cases --- test_logistic.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test_logistic.py b/test_logistic.py index e81e191..f64831f 100644 --- a/test_logistic.py +++ b/test_logistic.py @@ -1,5 +1,5 @@ from numpy.testing import assert_allclose - +import pytest from logistic import f # Add here your test for the logistic map @@ -15,12 +15,13 @@ def test_f_corner_cases(): result = f(x, r) assert_allclose(result, expected) -def test_generic_cases(): - cases = [ + + +@pytest.mark.parametrize('x, r, expected', [ (0.1,2.2,0.198), (0.2,3.4,0.544), (0.5,2,0.5) - ] - for x, r, expected in cases: - result = f(x, r) - assert_allclose(result, expected) \ No newline at end of file + ]) +def test_f_generic_values(x,r,expected): + result = f(x, r) + assert_allclose(result, expected) \ No newline at end of file From 5811a9a90a86fb82b5ddeb15dd4c1be66afa7bf9 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 29 Aug 2023 12:50:53 +0300 Subject: [PATCH 3/3] testing logistic iteration --- logistic.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/logistic.py b/logistic.py index fa3f9b5..da2f799 100644 --- a/logistic.py +++ b/logistic.py @@ -1,3 +1,8 @@ # Your code goes here def f(x,r): - return r * x * (1-x) \ No newline at end of file + return r * x * (1-x) + +def iterate_f(x,r,it): + result = [] + for _ in range(it): + result.append(f(result[-1],r)) \ No newline at end of file