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

modify unittest for changes in get_index_from_data_picked

parent b92d2e1d
Loading
Pipeline #2887 failed with stage
in 3 minutes and 3 seconds
This commit is part of merge request !159. Comments created here will be created in the context of that merge request.
......@@ -2,7 +2,70 @@ import numpy as np
from unittest import TestCase
from sohstationviewer.view.plotting.plotting_widget.plotting_widget_helper \
import get_total_miny_maxy
import get_total_miny_maxy, get_index_from_data_picked
class TestGetIndexFromTime(TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.plotting_data = {
'CH1': {
'times': [np.array([1, 2, 3, 4, 5, 6])],
'data': [np.array([1, 1, 0, 1, 1, 0])],
'chan_db_info': {'plotType': 'upDownDots'}
},
'CH2': {
'times': [np.array([1, 2, 3, 3, 5, 6])],
'data': [np.array([6, 9, 7, 4, 3, 9])],
'chan_db_info': {'plotType': 'linesDots'}
},
'CH3': {
'times': [np.array([1, 2, 3, 4, 5, 6])],
'data': [np.array([6, 9, 7, 4, 3, 9])],
'chan_db_info': {'plotType': 'dotForTime'}
}
}
def test_time_not_included(self):
real_idx = get_index_from_data_picked(
self.plotting_data['CH1'], 7, 1)
self.assertIsNone(real_idx)
def test_type_not_need_data_info(self):
# CH3 has plotType='dotForTime' in ["multiColorDots", "dotForTime"])
real_idx = get_index_from_data_picked(
self.plotting_data['CH3'], 4, 4)
self.assertEqual(real_idx, 3)
def test_type_need_data_info(self):
# CH2 has plotType='linesDots' not in ["multiColorDots", "dotForTime"])
with self.subTest('data not match time'):
real_idx = get_index_from_data_picked(
self.plotting_data['CH2'], 3, 5)
self.assertIsNone(real_idx)
with self.subTest('data match 1st value'):
real_idx = get_index_from_data_picked(
self.plotting_data['CH2'], 3, 7)
self.assertEqual(real_idx, 2)
with self.subTest('data match 2nd value'):
real_idx = get_index_from_data_picked(
self.plotting_data['CH2'], 3, 4)
self.assertEqual(real_idx, 3)
def test_type_up_down(self):
# CH1 has plotType='upDownDots'
with self.subTest('data not match time'):
real_idx = get_index_from_data_picked(
self.plotting_data['CH1'], 1, -0.5)
self.assertIsNone(real_idx)
with self.subTest('data=1 match time'):
real_idx = get_index_from_data_picked(
self.plotting_data['CH1'], 1, 0.5)
self.assertEqual(real_idx, 0)
with self.subTest('data=0 match time'):
real_idx = get_index_from_data_picked(
self.plotting_data['CH1'], 3, -0.5)
self.assertEqual(real_idx, 2)
class TestGetTotalMinyMaxy(TestCase):
......@@ -21,4 +84,4 @@ class TestGetTotalMinyMaxy(TestCase):
ret = get_total_miny_maxy(self.x, self.y, 8.1, 8.9)
self.assertEqual(ret[0], 0)
self.assertIsNone(ret[1])
self.assertIsNone(ret[2])
\ No newline at end of file
self.assertIsNone(ret[2])
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