changes to slides and exercises 2025

This commit is contained in:
Lisa Schwetlick 2025-09-22 14:51:11 +02:00
parent 6fdfdbb8b7
commit 6c782bdf30
4 changed files with 161 additions and 2 deletions

View file

@ -2,8 +2,6 @@ from numpy.testing import assert_allclose
from logistic import f
# Add here your test for the logistic map
def test_f_corner_cases():
# Test cases are (x, r, expected)
@ -14,3 +12,20 @@ def test_f_corner_cases():
for x, r, expected in cases:
result = f(x, r)
assert_allclose(result, expected)
# Hands on 1
#Add a new test for these generic cases using the for-loop pattern:
# x=0.1, r=2.2 => f(x, r)=0.198
# x=0.2, r=3.4 => f(x, r)=0.544
# x=0.5, r=2 => f(x, r)=0.5
# Hands on 2:
# parametrize the above test using @pytest.mark.parametrize
# Hands on 3
# Implement a function iterate_f that runs f for it iterations. Write tests for the following 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]