Browse Source

Analytics testing #210 (#319)

fixes basic python tests
pull/1/head
Alexandr Velikiy 6 years ago committed by Alexey Velikiy
parent
commit
acc5ea1a80
  1. 5
      analytics/analytics/models/model.py
  2. 5
      analytics/tests/test_dataset.py
  3. 47
      analytics/tests/test_utils.py

5
analytics/analytics/models/model.py

@ -31,7 +31,10 @@ class Model(ABC):
segment_length = abs(segment_to_index - segment_from_index)
segment_length_list.append(segment_length)
self.state['WINDOW_SIZE'] = math.ceil(max(segment_length_list) / 2)
if len(segment_length_list) > 0:
self.state['WINDOW_SIZE'] = math.ceil(max(segment_length_list) / 2)
else:
self.state['WINDOW_SIZE'] = 0
self.do_fit(dataframe, segments)
return self.state

5
analytics/tests/test_dataset.py

@ -24,10 +24,5 @@ class TestDataset(unittest.TestCase):
except ValueError:
self.fail('Model {} raised unexpectedly'.format(model_name))
def test_data_preparation(self):
data = [[1523889000000 + i, float('nan')] for i in range(10)]
self.assertTrue(prepare_data(data).empty) # TODO: raise exception
if __name__ == '__main__':
unittest.main()

47
analytics/tests/test_utils.py

@ -81,9 +81,11 @@ class TestUtils(unittest.TestCase):
data = []
pattern_index = []
window_size = 2
window_size_zero = 0
av_model = []
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)
def test_get_distribution_density(self):
segment = [1, 1, 1, 3, 5, 5, 5]
@ -95,39 +97,66 @@ class TestUtils(unittest.TestCase):
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)
jump_center = [10, 11]
self.assertIn(utils.find_jump_parameters(segment, 0)[0], jump_center)
self.assertIn(utils.find_parameters(segment, 0, 'jump')[0], jump_center)
def test_find_jump_parameters_height(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 = pd.Series(segment)
jump_height = [3.5, 4]
self.assertGreaterEqual(utils.find_jump_parameters(segment, 0)[1], jump_height[0])
self.assertLessEqual(utils.find_jump_parameters(segment, 0)[1], jump_height[1])
self.assertGreaterEqual(utils.find_parameters(segment, 0, 'jump')[1], jump_height[0])
self.assertLessEqual(utils.find_parameters(segment, 0, 'jump')[1], jump_height[1])
def test_find_jump_parameters_length(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 = pd.Series(segment)
jump_length = 2
self.assertEqual(utils.find_jump_parameters(segment, 0)[2], jump_length)
self.assertEqual(utils.find_parameters(segment, 0, 'jump')[2], jump_length)
def test_find_drop_parameters_center(self):
segment = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
segment = pd.Series(segment)
drop_center = [14, 15]
self.assertIn(utils.find_drop_parameters(segment, 0)[0], drop_center)
drop_center = [14, 15, 16]
self.assertIn(utils.find_parameters(segment, 0, 'drop')[0], drop_center)
def test_find_drop_parameters_height(self):
segment = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
segment = pd.Series(segment)
drop_height = [3.5, 4]
self.assertGreaterEqual(utils.find_drop_parameters(segment, 0)[1], drop_height[0])
self.assertLessEqual(utils.find_drop_parameters(segment, 0)[1], drop_height[1])
self.assertGreaterEqual(utils.find_parameters(segment, 0, 'drop')[1], drop_height[0])
self.assertLessEqual(utils.find_parameters(segment, 0, 'drop')[1], drop_height[1])
def test_find_drop_parameters_length(self):
segment = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
segment = pd.Series(segment)
drop_length = 2
self.assertEqual(utils.find_drop_parameters(segment, 0)[2], drop_length)
self.assertEqual(utils.find_parameters(segment, 0, 'drop')[2], drop_length)
def test_get_av_model_empty_data(self):
patterns_list = []
result = []
self.assertEqual(utils.get_av_model(patterns_list), result)
def test_find_jump_nan_data(self):
data = [np.NaN, np.NaN, np.NaN, np.NaN]
data = pd.Series(data)
length = 2
height = 3
length_zero = 0
height_zero = 0
result = []
self.assertEqual(utils.find_jump(data, height, length), result)
self.assertEqual(utils.find_jump(data, height_zero, length_zero), result)
def test_find_drop_nan_data(self):
data = [np.NaN, np.NaN, np.NaN, np.NaN]
data = pd.Series(data)
length = 2
height = 3
length_zero = 0
height_zero = 0
result = []
self.assertEqual(utils.find_drop(data, height, length), result)
self.assertEqual(utils.find_drop(data, height_zero, length_zero), result)
if __name__ == '__main__':
unittest.main()

Loading…
Cancel
Save