fix and test find_maxima function #4

Open
larissabe wants to merge 1 commit from larissabe/2024-heraklion-testing-debugging:main into main
2 changed files with 21 additions and 1 deletions

View file

@ -7,4 +7,14 @@ def find_maxima(x):
Output:
idx -- list of indices of the local maxima in x
"""
return []
local_maxima = []
for index, value in enumerate(x):
if index <= len(x)-2:
if x[index] > x[index+1] and x[index] > x[index-1]:
local_maxima.append(index)
if len(local_maxima) > 0:
return local_maxima

View file

@ -0,0 +1,10 @@
from local_maxima import find_maxima
import pytest
def test_find_maxima():
input_list = [0, 6, -2, 5, 1]
expected = [1, 3]
result = find_maxima(input_list)
assert result == expected