From 436acd66f556d44e39dea2f8d12e5b25b486f4a6 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 17:04:04 +0300 Subject: [PATCH 1/5] add logistic function --- testing_project/logistic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing_project/logistic.py b/testing_project/logistic.py index e49d1c2..cb3e06e 100644 --- a/testing_project/logistic.py +++ b/testing_project/logistic.py @@ -1 +1,4 @@ # Your code goes here + +def f(x, r): + return r * x * (1-x) -- 2.39.5 From 5ec2909b2658ea9cddcd70428f8c4a053110dc12 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 17:34:58 +0300 Subject: [PATCH 2/5] add test file for logistics --- testing_project/test_logistic.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testing_project/test_logistic.py b/testing_project/test_logistic.py index 100d824..7dc29c8 100644 --- a/testing_project/test_logistic.py +++ b/testing_project/test_logistic.py @@ -19,6 +19,15 @@ def test_f_corner_cases(): # x=0.2, r=3.4 => f(x, r)=0.544 # x=0.5, r=2 => f(x, r)=0.5 +def test_f_normal_cases(): + cases = [ + (.1, 2.2, .198), + (.2, 3.4, .544), + (.5, 2, .5), + ] + for x, r, expected in cases: + result = f(x, r) + assert_allclose(result, expected) # Hands on 2: # parametrize the above test using @pytest.mark.parametrize -- 2.39.5 From c11156fb805c200343d6f8ed2ce995526630421e Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 17:54:21 +0300 Subject: [PATCH 3/5] use decorator to parametrize --- testing_project/test_logistic.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/testing_project/test_logistic.py b/testing_project/test_logistic.py index 7dc29c8..c2ece9f 100644 --- a/testing_project/test_logistic.py +++ b/testing_project/test_logistic.py @@ -1,17 +1,13 @@ from numpy.testing import assert_allclose - +import pytest from logistic import f -def test_f_corner_cases(): +@pytest.mark.parametrize('x,r,expected', [(0, 1.1, 0),(1, 3.7, 0)]) +def test_f_corner_cases(x, r, expected): # Test cases are (x, r, expected) - cases = [ - (0, 1.1, 0), - (1, 3.7, 0), - ] - for x, r, expected in cases: - result = f(x, r) - assert_allclose(result, expected) + result = f(x, r) + assert_allclose(result, expected) # Hands on 1 #Add a new test for these generic cases using the for-loop pattern: -- 2.39.5 From 51eab93255c7746f24572d6e53c5d6f9ca696296 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 18:13:34 +0300 Subject: [PATCH 4/5] add iterate_f function and associated test func --- testing_project/logistic.py | 7 +++++++ testing_project/test_logistic.py | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/testing_project/logistic.py b/testing_project/logistic.py index cb3e06e..f5b0957 100644 --- a/testing_project/logistic.py +++ b/testing_project/logistic.py @@ -2,3 +2,10 @@ def f(x, r): return r * x * (1-x) + +def iterate_f(it, x, r): + result = [x] + for i in range(it): + x = f(x, r) + result.append(x) + return result diff --git a/testing_project/test_logistic.py b/testing_project/test_logistic.py index c2ece9f..d68934d 100644 --- a/testing_project/test_logistic.py +++ b/testing_project/test_logistic.py @@ -1,6 +1,6 @@ from numpy.testing import assert_allclose import pytest -from logistic import f +from logistic import f, iterate_f @pytest.mark.parametrize('x,r,expected', [(0, 1.1, 0),(1, 3.7, 0)]) @@ -34,3 +34,11 @@ def test_f_normal_cases(): # x=0.1, r=2.2, it=1 => iterate_f(it, x, r)=[0.1, 0.198] # x=0.2, r=3.4, it=4 => iterate_f(it, x, r)=[0.2, 0.544, 0.843418, 0.449019, 0.841163] # x=0.5, r=2, it=3 => iterate_f(it, x, r)=[0.5, 0.5, 0.5] +@pytest.mark.parametrize('x,r,it,expected', [ + (0.1, 2.2, 1, [0.1, 0.198]), + (0.2, 3.4, 4, [0.2, 0.544, 0.843418, 0.449019, 0.841163]), + (0.5, 2, 3, [0.5, 0.5, 0.5, 0.5]), +]) +def test_iterate_f(x, r, it, expected): + result = iterate_f(it, x, r) + assert_allclose(result, expected, rtol=1e-06) -- 2.39.5 From f8a43a0d479f10e6900b912a48287b7c5248c4e5 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 18:36:10 +0300 Subject: [PATCH 5/5] add test for logistic fit --- testing_project/test_logistic_fit.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 testing_project/test_logistic_fit.py diff --git a/testing_project/test_logistic_fit.py b/testing_project/test_logistic_fit.py new file mode 100644 index 0000000..6396ab1 --- /dev/null +++ b/testing_project/test_logistic_fit.py @@ -0,0 +1,9 @@ +from numpy.testing import assert_allclose +import pytest +from logistic_fit import fit_r +from logistic import iterate_f + +def test_logistic_fit(x0=0.3, r=3.421, it=23): + xs = iterate_f(it, x0, r) + r_fitted = fit_r(xs) + assert_allclose(r, r_fitted) -- 2.39.5