diff --git a/tests/test_model/test_handling_data.py b/tests/test_model/test_handling_data.py index db4da3274ca17e078d6323df8969edce7d5f1381..df763d67cb0d26076a98fe0fe58ea60755b88a77 100644 --- a/tests/test_model/test_handling_data.py +++ b/tests/test_model/test_handling_data.py @@ -30,7 +30,8 @@ from sohstationviewer.model.handling_data import ( checkChan, checkWFChan, checkSOHChan, - sortData + sortData, + squash_gaps ) from sohstationviewer.model.reftek.from_rt2ms.core import Reftek130 @@ -713,3 +714,64 @@ class TestSortData(TestCase): self.traces_list.append({'startTmEpoch': timestamp}) self.assertDictEqual(sortData(self.data_dict), self.data_dict) + +class TestSquashGaps(TestCase): + def test_two_gaps_squashed_chronological_order(self): + """ + Test squash_gaps - there are two gaps that can be merged and the gaps + are in chronological order with regards to their start time. Each + subtest case includes a gap that can't be squashed into either of the + other two gaps. + """ + with self.subTest('test_gaps_overlap_in_middle'): + gaps = [[-1000, -1000], [0, 75], [50, 100]] + expected = [[-1000, -1000], [0, 100]] + self.assertListEqual(squash_gaps(gaps), expected) + with self.subTest('test_one_gap_contained_in_another_gap'): + gaps = [[-1000, -1000], [0, 100], [25, 75]] + expected = [[-1000, -1000], [0, 100]] + self.assertListEqual(squash_gaps(gaps), expected) + with self.subTest('test_gaps_are_the_same'): + gaps = [[-1000, -1000], [0, 100], [0, 100]] + expected = [[-1000, -1000], [0, 100]] + self.assertListEqual(squash_gaps(gaps), expected) + with self.subTest('test_gaps_overlap_at_end_points'): + gaps = [[-1000, -1000], [0, 50], [50, 100]] + expected = [[-1000, -1000], [0, 100]] + self.assertListEqual(squash_gaps(gaps), expected) + + def test_two_gaps_can_be_squashed_reverse_chronological_order(self): + """ + Test squash_gaps - there are two gaps that can be merged and the gaps + are in reverse chronological order with regards to their start time. + Each subtest case includes a gap that can't be squashed into either of + the other two gaps. + """ + with self.subTest('test_gaps_overlap_in_middle'): + gaps = [[1000, 1000], [50, 100], [0, 75]] + expected = [[1000, 1000], [0, 100]] + self.assertListEqual(squash_gaps(gaps), expected) + with self.subTest('test_one_gap_contained_in_another_gap'): + gaps = [[1000, 1000], [25, 75], [0, 100]] + expected = [[1000, 1000], [0, 100]] + self.assertListEqual(squash_gaps(gaps), expected) + with self.subTest('test_gaps_are_the_same'): + gaps = [[1000, 1000], [0, 100], [0, 100]] + expected = [[1000, 1000], [0, 100]] + self.assertListEqual(squash_gaps(gaps), expected) + with self.subTest('test_gaps_overlap_at_end_points'): + gaps = [[1000, 1000], [50, 100], [0, 50]] + expected = [[1000, 1000], [0, 100]] + self.assertListEqual(squash_gaps(gaps), expected) + + def test_no_gap_can_be_squashed_chronological_order(self): + gaps = [[1, 100], [101, 200], [201, 300], [301, 400]] + self.assertListEqual(squash_gaps(gaps), gaps) + + def test_no_gap_can_be_squashed_reverse_chronological_order(self): + gaps = [[301, 400], [201, 300], [101, 200], [1, 100]] + self.assertListEqual(squash_gaps(gaps), gaps) + + def test_no_gap_in_data(self): + gaps = [] + self.assertListEqual(squash_gaps(gaps), [])