From 9a87a89d7bc4cc6feec8718a0f5fc11b50a832ce Mon Sep 17 00:00:00 2001
From: kienle <kienle@passcal.nmt.edu>
Date: Wed, 28 Sep 2022 14:37:20 -0600
Subject: [PATCH] Add tests for squash_gaps

---
 tests/test_model/test_handling_data.py | 64 +++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)

diff --git a/tests/test_model/test_handling_data.py b/tests/test_model/test_handling_data.py
index db4da3274..df763d67c 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), [])
-- 
GitLab