Skip to content
Snippets Groups Projects
Commit 45a79030 authored by Kien Le's avatar Kien Le
Browse files

Add breaking tests for downsample_waveform_chan

parent 12ad2f4d
No related branches found
No related tags found
1 merge request!33Add tests and refactor trim_downsample_WFChan
......@@ -14,6 +14,7 @@ from sohstationviewer.model.handling_data import (
get_eachDay5MinList,
get_trimTPSData,
trim_waveform_data,
downsample_waveform_chan
)
ORIGINAL_CHAN_SIZE_LIMIT = const.CHAN_SIZE_LIMIT
......@@ -148,17 +149,65 @@ class TestDownsampleWaveformData(TestCase):
trace['data_f'] = data_file_name
self.traces_info.append(trace)
self.start_time = 2500
self.end_time = 7500
self.start_time = 2550
self.end_time = 7550
self.trimmed_traces_list = trim_waveform_data(
self.channel_data, self.start_time, self.end_time
)
@patch('sohstationviewer.model.handling_data.downsample', wraps=downsample)
def test_data_is_downsampled(self, mock_downsample):
const.CHAN_SIZE_LIMIT = 1000
trim_downsample_WFChan(self.channel_data, self.start_time,
self.end_time, True)
downsample_waveform_chan(self.channel_data, self.trimmed_traces_list,
self.start_time, self.end_time, True)
self.assertTrue(mock_downsample.called)
const.CHAN_SIZE_LIMIT = ORIGINAL_CHAN_SIZE_LIMIT
def test_all_traces_handled(self):
downsampled_times, downsampled_data = downsample_waveform_chan(
self.channel_data, self.trimmed_traces_list,
self.start_time, self.end_time, True
)
self.assertEqual(len(downsampled_times), 51)
self.assertEqual(len(downsampled_data), 51)
def test_downsampling_not_needed(self):
downsampled_times, downsampled_data = downsample_waveform_chan(
self.channel_data, self.trimmed_traces_list,
self.start_time, self.end_time, True
)
with self.subTest('test_data_points_outside_time_range_removed'):
self.assertEqual(downsampled_times.pop[0].size, 50)
self.assertEqual(downsampled_times.pop[-1].size, 50)
self.assertEqual(downsampled_data.pop[0].size, 50)
self.assertEqual(downsampled_data.pop[-1].size, 50)
with self.subTest('test_intermediate_data_points_not_removed'):
self.assertTrue(
all(times.size == 100 for times in downsampled_times)
)
self.assertTrue(
all(data.size == 100 for data in downsampled_times)
)
def test_trace_list_empty(self):
self.trimmed_traces_list = []
downsampled_times, downsampled_data = downsample_waveform_chan(
self.channel_data, self.trimmed_traces_list,
self.start_time, self.end_time, True
)
self.assertListEqual(downsampled_times, [])
self.assertListEqual(downsampled_data, [])
def test_end_time_earlier_than_start_time(self):
self.start_time, self.end_time = self.end_time, self.start_time
downsampled_times, downsampled_data = downsample_waveform_chan(
self.channel_data, self.trimmed_traces_list,
self.start_time, self.end_time, True
)
self.assertListEqual(downsampled_times, [])
self.assertListEqual(downsampled_data, [])
class TestTrimDownsampleWfChan(TestCase):
def setUp(self) -> None:
......
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