Skip to content

Commit 90d9d1f

Browse files
authored
Merge pull request #393 from Limmen/plotting
unit test plotting_util
2 parents 6d3ba6f + b5584f5 commit 90d9d1f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from csle_common.util.plotting_util import PlottingUtil
2+
from scipy import stats
3+
import numpy as np
4+
5+
6+
class TestPlottingUtilSuite:
7+
"""
8+
Test suite for plotting util
9+
"""
10+
11+
def test_running_average(self) -> None:
12+
"""
13+
Test the function used to compute the running average of the last N elements of a vector x
14+
15+
:return: None
16+
"""
17+
x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
18+
N = 3
19+
expected = np.array([1, 2, 3, 3, 4, 5, 6, 7, 8, 9])
20+
result = PlottingUtil.running_average(x, N)
21+
assert result.any() == expected.any()
22+
23+
def test_mean_confidence_interval(self) -> None:
24+
"""
25+
Test function that computes confidence intervals
26+
27+
:return: None
28+
"""
29+
data = np.array([1, 2, 3, 4, 5])
30+
mean, h = PlottingUtil.mean_confidence_interval(data=data, confidence=0.95)
31+
expected_mean = np.mean(data)
32+
expected_se = stats.sem(data)
33+
expected_h = expected_se * stats.t.ppf((1 + 0.95) / 2.0, len(data) - 1)
34+
assert expected_mean == mean
35+
assert expected_h == h
36+
37+
def test_min_max_norm(self) -> None:
38+
"""
39+
Test function that computes min-max normalization of a vector
40+
41+
:return: None
42+
"""
43+
vec = np.array([1, 2, 3, 4, 5])
44+
min_val = 1
45+
max_val = 5
46+
expected = np.array([0.0, 0.25, 0.5, 0.75, 1.0])
47+
result = PlottingUtil.min_max_norm(vec, max_val, min_val)
48+
assert result.any() == expected.any()

0 commit comments

Comments
 (0)