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
Showing only changes of commit 3a3a0438b4 - Show all commits

View file

@ -7,4 +7,14 @@ 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 []
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