added local maxima function #5

Open
annala wants to merge 2 commits from annala/2025-plovdiv-testing-debugging:fix-1 into main
3 changed files with 56 additions and 4 deletions
Showing only changes of commit c62e1e8797 - Show all commits

View file

@ -1,6 +1,11 @@
from first import times_3
def test_times_3_integer(): def test_times_3_integer():
pass result = times_3([1])
assert result == [1, 1, 1]
def test_times_3_string(): def test_times_3_string():
pass result = times_3([1])
assert result == [2]

View file

@ -4,12 +4,18 @@ def find_maxima(x):
Input arguments: Input arguments:
x -- 1D list of real numbers x -- 1D list of real numbers
Output: Output:
idx -- list of indices of the local maxima in x idx -- list of indices of the local maxima in x
""" """
return [] maxima = []
for index in range(len(x)-2):
if x[index+1] > x[index] and x[index +1] > x[index+2]:
maxima.append(index+1)
return maxima
if __name__ == "__main__": if __name__ == "__main__":
x = [1, 2, 3] x = [1, 2, 2, 1]
print(find_maxima(x)) print(find_maxima(x))

View file

@ -0,0 +1,41 @@
from local_maxima import find_maxima
def test_local_maxima_empty():
value = []
expected = []
result = find_maxima(value)
assert result == expected
def test_local_maxima_plateau():
value = [1, 2, 2, 1]
expected = []
result = find_maxima(value)
assert result == expected
def test_local_maxima_array1():
value = [1, 3, 5, 2, 1]
expected = [2]
result = find_maxima(value)
assert result == expected
def test_local_maxima_array2():
value = [5, 4, 4, 5]
expected = []
result = find_maxima(value)
assert result == expected