fix and test find_maxima function

This commit is contained in:
ASPP Student 2024-08-27 16:10:28 +03:00
parent c5b36a07bf
commit 3a3a0438b4
2 changed files with 21 additions and 1 deletions

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