-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest_maxima.py
42 lines (36 loc) · 1015 Bytes
/
test_maxima.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy as np
from maxima import find_maxima
def test_simple_sequence_two_maxima():
inp = [0, 1, 2, 1, 2, 1, 0]
out = find_maxima(inp)
exp = [2, 4]
assert exp == out
def test_simple_sequence_one_maximum():
inp = [-i**2 for i in range(-3, 4)]
out = find_maxima(inp)
exp = [3]
assert exp == out
def test_sine_wave():
inp = [np.sin(2*alpha) for alpha in np.linspace(0.0, 5.0, 100)]
out = find_maxima(inp)
exp = [16,78]
assert exp == out
def test_max_on_both_borders():
inp = [4, 2, 1, 3, 1, 2]
out = find_maxima(inp)
exp = [0,3,5]
assert exp == out
# additional tests for
# - max on both borders
# x = [4, 2, 1, 3, 1, 2]
# - max on both borders, absolute max on right border
# x = [4, 2, 1, 3, 1, 5]
# - one max (absolute) on left border
# x = [4, 2, 1, 3, 1]
# - plateau
# x = [1, 2, 2, 1]
# (decide for a sensible output in this case)
# - test cases for plateau
# x = [1, 2, 2, 3, 1]
# x = [1, 3, 2, 2, 1]
# x = [3, 2, 2, 3]