|
|
@ -4,6 +4,8 @@ import numpy as np |
|
|
|
import pandas as pd |
|
|
|
import pandas as pd |
|
|
|
import math |
|
|
|
import math |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RELATIVE_TOLERANCE = 1e-1 |
|
|
|
|
|
|
|
|
|
|
|
class TestUtils(unittest.TestCase): |
|
|
|
class TestUtils(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
|
|
#example test for test's workflow purposes |
|
|
|
#example test for test's workflow purposes |
|
|
@ -14,8 +16,7 @@ class TestUtils(unittest.TestCase): |
|
|
|
segment = [1, 2, 0, 6, 8, 5, 3] |
|
|
|
segment = [1, 2, 0, 6, 8, 5, 3] |
|
|
|
utils_result = utils.find_confidence(segment) |
|
|
|
utils_result = utils.find_confidence(segment) |
|
|
|
result = 1.6 |
|
|
|
result = 1.6 |
|
|
|
relative_tolerance = 1e-2 |
|
|
|
self.assertTrue(math.isclose(utils_result, result, rel_tol = RELATIVE_TOLERANCE)) |
|
|
|
self.assertTrue(math.isclose(utils_result, result, rel_tol = relative_tolerance)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_confidence_all_nan_value(self): |
|
|
|
def test_confidence_all_nan_value(self): |
|
|
|
segment = [np.NaN, np.NaN, np.NaN, np.NaN] |
|
|
|
segment = [np.NaN, np.NaN, np.NaN, np.NaN] |
|
|
@ -25,8 +26,7 @@ class TestUtils(unittest.TestCase): |
|
|
|
data = [np.NaN, np.NaN, 0, 8] |
|
|
|
data = [np.NaN, np.NaN, 0, 8] |
|
|
|
utils_result = utils.find_confidence(data) |
|
|
|
utils_result = utils.find_confidence(data) |
|
|
|
result = 1.6 |
|
|
|
result = 1.6 |
|
|
|
relative_tolerance = 1e-2 |
|
|
|
self.assertTrue(math.isclose(utils_result, result, rel_tol = RELATIVE_TOLERANCE)) |
|
|
|
self.assertTrue(math.isclose(utils_result, result, rel_tol = relative_tolerance)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_interval_all_normal_value(self): |
|
|
|
def test_interval_all_normal_value(self): |
|
|
|
data = [1, 2, 1, 2, 4, 1, 2, 4, 5, 6] |
|
|
|
data = [1, 2, 1, 2, 4, 1, 2, 4, 5, 6] |
|
|
@ -87,12 +87,6 @@ class TestUtils(unittest.TestCase): |
|
|
|
self.assertEqual(utils.get_convolve(pattern_index, av_model, data, window_size), result) |
|
|
|
self.assertEqual(utils.get_convolve(pattern_index, av_model, data, window_size), result) |
|
|
|
self.assertEqual(utils.get_convolve(pattern_index, av_model, data, window_size_zero), result) |
|
|
|
self.assertEqual(utils.get_convolve(pattern_index, av_model, data, window_size_zero), result) |
|
|
|
|
|
|
|
|
|
|
|
def test_get_distribution_density(self): |
|
|
|
|
|
|
|
segment = [1, 1, 1, 3, 5, 5, 5] |
|
|
|
|
|
|
|
segment = pd.Series(segment) |
|
|
|
|
|
|
|
result = (3, 5, 1) |
|
|
|
|
|
|
|
self.assertEqual(utils.get_distribution_density(segment), result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_jump_parameters_center(self): |
|
|
|
def test_find_jump_parameters_center(self): |
|
|
|
segment = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5] |
|
|
|
segment = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5] |
|
|
|
segment = pd.Series(segment) |
|
|
|
segment = pd.Series(segment) |
|
|
@ -157,6 +151,44 @@ class TestUtils(unittest.TestCase): |
|
|
|
result = [] |
|
|
|
result = [] |
|
|
|
self.assertEqual(utils.find_drop(data, height, length), result) |
|
|
|
self.assertEqual(utils.find_drop(data, height, length), result) |
|
|
|
self.assertEqual(utils.find_drop(data, height_zero, length_zero), result) |
|
|
|
self.assertEqual(utils.find_drop(data, height_zero, length_zero), result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_distribution_density(self): |
|
|
|
|
|
|
|
segment = [1, 1, 1, 3, 5, 5, 5] |
|
|
|
|
|
|
|
segment = pd.Series(segment) |
|
|
|
|
|
|
|
result = (3, 5, 1) |
|
|
|
|
|
|
|
self.assertEqual(utils.get_distribution_density(segment), result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_distribution_density_right(self): |
|
|
|
|
|
|
|
data = [1.0, 5.0, 5.0, 4.0] |
|
|
|
|
|
|
|
data = pd.Series(data) |
|
|
|
|
|
|
|
median = 3.0 |
|
|
|
|
|
|
|
max_line = 5.0 |
|
|
|
|
|
|
|
min_line = 1.0 |
|
|
|
|
|
|
|
utils_result = utils.get_distribution_density(data) |
|
|
|
|
|
|
|
self.assertTrue(math.isclose(utils_result[0], median, rel_tol = RELATIVE_TOLERANCE)) |
|
|
|
|
|
|
|
self.assertTrue(math.isclose(utils_result[1], max_line, rel_tol = RELATIVE_TOLERANCE)) |
|
|
|
|
|
|
|
self.assertTrue(math.isclose(utils_result[2], min_line, rel_tol = RELATIVE_TOLERANCE)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_distribution_density_left(self): |
|
|
|
|
|
|
|
data = [1.0, 1.0, 2.0, 1.0, 5.0] |
|
|
|
|
|
|
|
data = pd.Series(data) |
|
|
|
|
|
|
|
median = 3.0 |
|
|
|
|
|
|
|
max_line = 5.0 |
|
|
|
|
|
|
|
min_line = 1.0 |
|
|
|
|
|
|
|
utils_result = utils.get_distribution_density(data) |
|
|
|
|
|
|
|
self.assertTrue(math.isclose(utils_result[0], median, rel_tol = RELATIVE_TOLERANCE)) |
|
|
|
|
|
|
|
self.assertTrue(math.isclose(utils_result[1], max_line, rel_tol = RELATIVE_TOLERANCE)) |
|
|
|
|
|
|
|
self.assertTrue(math.isclose(utils_result[2], min_line, rel_tol = RELATIVE_TOLERANCE)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_distribution_density_short_data(self): |
|
|
|
|
|
|
|
data = [1.0, 5.0] |
|
|
|
|
|
|
|
data = pd.Series(data) |
|
|
|
|
|
|
|
segment = [1.0] |
|
|
|
|
|
|
|
segment = pd.Series(segment) |
|
|
|
|
|
|
|
utils_result_data = utils.get_distribution_density(data) |
|
|
|
|
|
|
|
utils_result_segment = utils.get_distribution_density(segment) |
|
|
|
|
|
|
|
self.assertEqual(len(utils_result_data), 3) |
|
|
|
|
|
|
|
self.assertEqual(utils_result_segment, (0, 0, 0)) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
if __name__ == '__main__': |
|
|
|
unittest.main() |
|
|
|
unittest.main() |
|
|
|