fix-1 #3
3 changed files with 23 additions and 8 deletions
|
@ -7,4 +7,14 @@ def find_maxima(x):
|
|||
Output:
|
||||
idx -- list of indices of the local maxima in x
|
||||
"""
|
||||
return []
|
||||
sol = []
|
||||
for idx, num in enumerate(x):
|
||||
if idx == 0 and num => x[idx+1]:
|
||||
sol.append(idx)
|
||||
elif idx == len(x)-1 and num => x[idx-1]:
|
||||
sol.append(idx)
|
||||
else:
|
||||
if x[idx-1] <= num and num => x[idx+1]:
|
||||
sol.append(idx)
|
||||
|
||||
return sol
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
# Your code goes here
|
||||
|
||||
def f(x, r):
|
||||
return r * x * (1-x)
|
||||
|
|
|
@ -13,12 +13,15 @@ def test_f_corner_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
|
||||
|
||||
def test_f_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)
|
||||
|
||||
# Hands on 2:
|
||||
# parametrize the above test using @pytest.mark.parametrize
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue