-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yuhu-kth
committed
Jul 17, 2024
1 parent
b89bcf0
commit b5584f5
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
simulation-system/libs/csle-common/tests/test_plotting_util.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from csle_common.util.plotting_util import PlottingUtil | ||
from scipy import stats | ||
import numpy as np | ||
|
||
|
||
class TestPlottingUtilSuite: | ||
""" | ||
Test suite for plotting util | ||
""" | ||
|
||
def test_running_average(self) -> None: | ||
""" | ||
Test the function used to compute the running average of the last N elements of a vector x | ||
:return: None | ||
""" | ||
x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | ||
N = 3 | ||
expected = np.array([1, 2, 3, 3, 4, 5, 6, 7, 8, 9]) | ||
result = PlottingUtil.running_average(x, N) | ||
assert result.any() == expected.any() | ||
|
||
def test_mean_confidence_interval(self) -> None: | ||
""" | ||
Test function that computes confidence intervals | ||
:return: None | ||
""" | ||
data = np.array([1, 2, 3, 4, 5]) | ||
mean, h = PlottingUtil.mean_confidence_interval(data=data, confidence=0.95) | ||
expected_mean = np.mean(data) | ||
expected_se = stats.sem(data) | ||
expected_h = expected_se * stats.t.ppf((1 + 0.95) / 2.0, len(data) - 1) | ||
assert expected_mean == mean | ||
assert expected_h == h | ||
|
||
def test_min_max_norm(self) -> None: | ||
""" | ||
Test function that computes min-max normalization of a vector | ||
:return: None | ||
""" | ||
vec = np.array([1, 2, 3, 4, 5]) | ||
min_val = 1 | ||
max_val = 5 | ||
expected = np.array([0.0, 0.25, 0.5, 0.75, 1.0]) | ||
result = PlottingUtil.min_max_norm(vec, max_val, min_val) | ||
assert result.any() == expected.any() |