fix-1 #4
2 changed files with 20 additions and 6 deletions
|
@ -7,4 +7,12 @@ def find_maxima(x):
|
||||||
Output:
|
Output:
|
||||||
idx -- list of indices of the local maxima in x
|
idx -- list of indices of the local maxima in x
|
||||||
"""
|
"""
|
||||||
return []
|
idx = []
|
||||||
|
for i in range(len(x)):
|
||||||
|
if i == 0 and x[i] > x[i+1]:
|
||||||
|
idx.append(i)
|
||||||
|
elif i != len(x)-1 and x[i] > x[i-1] and x[i] > x[i+1]:
|
||||||
|
idx.append(i)
|
||||||
|
elif i== len(x)-1 and x[i] > x[i-1]:
|
||||||
|
idx.append(i)
|
||||||
|
return idx
|
|
@ -16,15 +16,21 @@ def test_find_maxima_edges():
|
||||||
|
|
||||||
|
|
||||||
def test_find_maxima_empty():
|
def test_find_maxima_empty():
|
||||||
|
values = [1,2,2,1]
|
||||||
|
expected = [1]
|
||||||
|
maxima = find_maxima(values)
|
||||||
|
assert maxima == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_maxima_plateau():
|
||||||
values = []
|
values = []
|
||||||
expected = []
|
expected = []
|
||||||
maxima = find_maxima(values)
|
maxima = find_maxima(values)
|
||||||
assert maxima == expected
|
assert maxima == expected
|
||||||
|
|
||||||
|
|
||||||
def test_find_maxima_plateau():
|
|
||||||
raise Exception('not yet implemented')
|
|
||||||
|
|
||||||
|
|
||||||
def test_find_maxima_not_a_plateau():
|
def test_find_maxima_not_a_plateau():
|
||||||
raise Exception('not yet implemented')
|
values = []
|
||||||
|
expected = []
|
||||||
|
maxima = find_maxima(values)
|
||||||
|
assert maxima == expected
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue