added local maxima function #5
2 changed files with 12 additions and 0 deletions
|
@ -1 +1,3 @@
|
||||||
# Your code goes here
|
# Your code goes here
|
||||||
|
def f(x, r):
|
||||||
|
return x*r*(1 -x)
|
|
@ -18,6 +18,16 @@ def test_f_corner_cases():
|
||||||
# x=0.1, r=2.2 => f(x, r)=0.198
|
# x=0.1, r=2.2 => f(x, r)=0.198
|
||||||
# x=0.2, r=3.4 => f(x, r)=0.544
|
# x=0.2, r=3.4 => f(x, r)=0.544
|
||||||
# x=0.5, r=2 => f(x, r)=0.5
|
# x=0.5, r=2 => f(x, r)=0.5
|
||||||
|
def test_f_generic_cases():
|
||||||
|
# Test cases are (x, r, expected)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
# Hands on 2:
|
# Hands on 2:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue