forked from wolph/python-progressbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_algorithms.py
More file actions
58 lines (46 loc) · 1.35 KB
/
test_algorithms.py
File metadata and controls
58 lines (46 loc) · 1.35 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from datetime import timedelta
import pytest
from progressbar import algorithms
def test_ema_initialization() -> None:
ema = algorithms.ExponentialMovingAverage()
assert ema.alpha == 0.5
assert ema.value == 0
@pytest.mark.parametrize(
'alpha, new_value, expected',
[
(0.5, 10, 5),
(0.1, 20, 2),
(0.9, 30, 27),
(0.3, 15, 4.5),
(0.7, 40, 28),
(0.5, 0, 0),
(0.2, 100, 20),
(0.8, 50, 40),
],
)
def test_ema_update(alpha, new_value: float, expected) -> None:
ema = algorithms.ExponentialMovingAverage(alpha)
result = ema.update(new_value, timedelta(seconds=1))
assert result == expected
def test_dema_initialization() -> None:
dema = algorithms.DoubleExponentialMovingAverage()
assert dema.alpha == 0.5
assert dema.ema1 == 0
assert dema.ema2 == 0
@pytest.mark.parametrize(
'alpha, new_value, expected',
[
(0.5, 10, 7.5),
(0.1, 20, 3.8),
(0.9, 30, 29.7),
(0.3, 15, 7.65),
(0.5, 0, 0),
(0.2, 100, 36.0),
(0.8, 50, 48.0),
],
)
def test_dema_update(alpha, new_value: float, expected) -> None:
dema = algorithms.DoubleExponentialMovingAverage(alpha)
result = dema.update(new_value, timedelta(seconds=1))
assert result == expected
# Additional test functions can be added here as needed.