Skip to content
Snippets Groups Projects
Commit a2c0a7da authored by Lan Dam's avatar Lan Dam
Browse files

modify unittest to work with list returned from get_index_from_data_picked

parent b0722597
No related branches found
No related tags found
1 merge request!165Fix SOH info not show for bottom of Jerk/DPS and display all info lines for the case data point clicked matches more than one SOH lines.
Pipeline #2925 passed with stage
in 2 minutes and 18 seconds
...@@ -5,13 +5,13 @@ from sohstationviewer.view.plotting.plotting_widget.plotting_widget_helper \ ...@@ -5,13 +5,13 @@ from sohstationviewer.view.plotting.plotting_widget.plotting_widget_helper \
import get_total_miny_maxy, get_index_from_data_picked import get_total_miny_maxy, get_index_from_data_picked
class TestGetIndexFromTime(TestCase): class TestGetIndexFromDataPicked(TestCase):
@classmethod @classmethod
def setUpClass(cls) -> None: def setUpClass(cls) -> None:
cls.plotting_data = { cls.plotting_data = {
'CH1': { 'CH1': {
'times': [np.array([1, 2, 3, 4, 5, 6])], 'times': [np.array([1, 2, 3, 4, 5, 6, 6])],
'data': [np.array([1, 1, 0, 1, 1, 0])], 'data': [np.array([1, 1, 0, 1, 1, 0, 0])],
'chan_db_info': {'plotType': 'upDownDots'} 'chan_db_info': {'plotType': 'upDownDots'}
}, },
'CH2': { 'CH2': {
...@@ -27,45 +27,51 @@ class TestGetIndexFromTime(TestCase): ...@@ -27,45 +27,51 @@ class TestGetIndexFromTime(TestCase):
} }
def test_time_not_included(self): def test_time_not_included(self):
real_idx = get_index_from_data_picked( real_idxes = get_index_from_data_picked(
self.plotting_data['CH1'], 7, 1) self.plotting_data['CH1'], 7, 1)
self.assertIsNone(real_idx) self.assertEqual(len(real_idxes), 0)
def test_type_not_need_data_info(self): def test_type_not_need_data_val(self):
# CH3 has plotType='dotForTime' in ["multiColorDots", "dotForTime"]) # CH3 has plotType='dotForTime'
real_idx = get_index_from_data_picked( # which is in ["multiColorDots", "dotForTime"])
real_idxes = get_index_from_data_picked(
self.plotting_data['CH3'], 4, 4) self.plotting_data['CH3'], 4, 4)
self.assertEqual(real_idx, 3) self.assertEqual(real_idxes.tolist(), [3])
def test_type_need_data_info(self): def test_type_need_data_val(self):
# CH2 has plotType='linesDots' not in ["multiColorDots", "dotForTime"]) # CH2 has plotType='linesDots' not in ["multiColorDots", "dotForTime"])
with self.subTest('data not match time'): with self.subTest('data not match time'):
real_idx = get_index_from_data_picked( real_idxes = get_index_from_data_picked(
self.plotting_data['CH2'], 3, 5) self.plotting_data['CH2'], 3, 5)
self.assertIsNone(real_idx) self.assertEqual(len(real_idxes), 0)
with self.subTest('data match 1st value'): with self.subTest('data match 1st value'):
real_idx = get_index_from_data_picked( real_idxes = get_index_from_data_picked(
self.plotting_data['CH2'], 3, 7) self.plotting_data['CH2'], 3, 7)
self.assertEqual(real_idx, 2) self.assertEqual(real_idxes.tolist(), [2])
with self.subTest('data match 2nd value'): with self.subTest('data match 2nd value'):
real_idx = get_index_from_data_picked( real_idxes = get_index_from_data_picked(
self.plotting_data['CH2'], 3, 4) self.plotting_data['CH2'], 3, 4)
self.assertEqual(real_idx, 3) self.assertEqual(real_idxes.tolist(), [3])
def test_type_up_down(self): def test_type_up_down(self):
# CH1 has plotType='upDownDots' # CH1 has plotType='upDownDots'
with self.subTest('data not match time'): with self.subTest('data not match time'):
real_idx = get_index_from_data_picked( real_idxes = get_index_from_data_picked(
self.plotting_data['CH1'], 1, -0.5) self.plotting_data['CH1'], 1, -0.5)
self.assertIsNone(real_idx) self.assertEqual(len(real_idxes), 0)
with self.subTest('data=1 match time'): with self.subTest('data=1 match time'):
real_idx = get_index_from_data_picked( real_idxes = get_index_from_data_picked(
self.plotting_data['CH1'], 1, 0.5) self.plotting_data['CH1'], 1, 0.5)
self.assertEqual(real_idx, 0) self.assertEqual(real_idxes.tolist(), [0])
with self.subTest('data=0 match time'): with self.subTest('data=0 match time'):
real_idx = get_index_from_data_picked( real_idxes = get_index_from_data_picked(
self.plotting_data['CH1'], 3, -0.5) self.plotting_data['CH1'], 3, -0.5)
self.assertEqual(real_idx, 2) self.assertEqual(real_idxes.tolist(), [2])
def test_2_overlapped_points(self):
real_idxes = get_index_from_data_picked(
self.plotting_data['CH1'], 6, -0.5)
self.assertEqual(real_idxes.tolist(), [5, 6])
class TestGetTotalMinyMaxy(TestCase): class TestGetTotalMinyMaxy(TestCase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment