Partly fixes issue #8
2 changed files with 33 additions and 4 deletions
|
@ -7,4 +7,27 @@ def find_maxima(x):
|
|||
Output:
|
||||
idx -- list of indices of the local maxima in x
|
||||
"""
|
||||
return []
|
||||
maxima = []
|
||||
for idx in range(len(x)):
|
||||
if idx == 0:
|
||||
if x[idx] >= x[idx+1]:
|
||||
maxima.append(idx)
|
||||
elif idx == len(x)-1:
|
||||
if x[idx] >= x[idx-1]:
|
||||
maxima.append(idx)
|
||||
else:
|
||||
if x[idx] >= x[idx+1] and x[idx] >= x[idx-1]:
|
||||
maxima.append(idx)
|
||||
return maxima
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
values = [
|
||||
[1, 3, -2, 0, 2, 1],
|
||||
[4,2,1,3,1,5],
|
||||
[],
|
||||
[1,2,2,1],
|
||||
[1,2,2,3,1],
|
||||
]
|
||||
for value in values:
|
||||
print(find_maxima(value))
|
||||
|
|
|
@ -23,8 +23,14 @@ def test_find_maxima_empty():
|
|||
|
||||
|
||||
def test_find_maxima_plateau():
|
||||
raise Exception('not yet implemented')
|
||||
|
||||
values = [1,2,2,1]
|
||||
expected = [1,2]
|
||||
maxima = find_maxima(values)
|
||||
assert maxima == expected
|
||||
|
||||
|
||||
def test_find_maxima_not_a_plateau():
|
||||
raise Exception('not yet implemented')
|
||||
values = [1,2,2,3,1]
|
||||
expected = [3]
|
||||
maxima = find_maxima(values)
|
||||
assert maxima == expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue