Skip to content

Commit 3b16f6b

Browse files
author
Jaime Céspedes Sisniega
authored
Merge pull request #179 from IFCA/feature-test-stats
Feature test stats
2 parents 94e799a + 222de32 commit 3b16f6b

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""Test stats module."""
2+
3+
from typing import List, Union
4+
5+
import numpy as np # type: ignore
6+
import pytest # type: ignore
7+
8+
from frouros.utils.stats import CircularMean, Mean
9+
10+
11+
@pytest.mark.parametrize(
12+
"size, values, expected_mean_steps",
13+
[
14+
(1, [5, 10, 6, 4, 14], [5.0, 10.0, 6.0, 4.0, 14.0]),
15+
(3, [5, 10, 6, 4, 14], [5.0, 7.5, 7.0, 6.66666667, 8.0]),
16+
(6, [5, 10, 6, 4, 14], [5.0, 7.5, 7, 6.25, 7.8]),
17+
],
18+
)
19+
def test_circular_mean(
20+
size: int,
21+
values: List[Union[int, float]],
22+
expected_mean_steps: List[Union[int, float]],
23+
) -> None:
24+
"""Test circular mean.
25+
26+
:param size: size value
27+
:type size: int
28+
:param values: values
29+
:type values: List[Union[int, float]]
30+
:param expected_mean_steps: expected mean step values
31+
:type expected_mean_steps: List[Union[int, float]]
32+
"""
33+
mean = CircularMean(size=size)
34+
35+
for value, expected_mean_step in zip(values, expected_mean_steps):
36+
mean.update(value=value)
37+
assert np.isclose(mean.get(), expected_mean_step)
38+
39+
40+
@pytest.mark.parametrize(
41+
"values, expected_mean_steps",
42+
[
43+
([5, 10, 6, 4, 14], [5.0, 7.5, 7, 6.25, 7.8]),
44+
([-5, 10, -6, 4, -14], [-5.0, 2.5, -0.33333334, 0.75, -2.2]),
45+
],
46+
)
47+
def test_mean(
48+
values: List[Union[int, float]],
49+
expected_mean_steps: List[Union[int, float]],
50+
) -> None:
51+
"""Test mean.
52+
53+
:param values: values
54+
:type values: List[Union[int, float]]
55+
:param expected_mean_steps: expected mean step values
56+
:type expected_mean_steps: List[Union[int, float]]
57+
"""
58+
mean = Mean()
59+
60+
for value, expected_mean_step in zip(values, expected_mean_steps):
61+
mean.update(value=value)
62+
assert np.isclose(mean.get(), expected_mean_step)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "frouros"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
description = "A Python library for drift detection in Machine Learning problems"
55
authors = [
66
{name = "Jaime Céspedes Sisniega", email = "[email protected]"}

0 commit comments

Comments
 (0)