예제 #1
0
 def testNormalize5(self):
     ss = [(489, 589), (1966, 2066), (2786, 2886), (0, 0), (3889, 3972), (3998, 4098),
           (6441, 6541), (6937, 7054), (7392, 7492), (8154, 8254), (9046, 9146)]
     s = SegmentList(iter=ss)
     s.normalize()
     self.assertEqual(len(s), len([x for x in ss if x[1] - x[0] > 0]))
     self.assertEqual(s.sum(), 1000)
     s2 = SegmentList(iter=ss)
     s2.merge(-1)
     self.assertEqual(s, s2)
예제 #2
0
    def testNormalize2(self):
        '''overlapping segments.'''

        ss = [(x, x + 1000) for x in range(0, 1000, 100)]
        random.shuffle(ss)
        s = SegmentList()
        for start, end in ss:
            s.add(start, end)
        s.normalize()
        self.assertEqual(len(s), 1)
        self.assertEqual(s.sum(), 1900)
예제 #3
0
    def testNormalizeEmpty(self):
        '''non-overlapping segments.'''

        s = SegmentList()
        self.assertEqual(len(s), 0)
        s.normalize()
        self.assertEqual(len(s), 0)
        self.assertEqual(s.isNormalized, 1)
        s2 = SegmentList()
        s2.merge(-1)
        self.assertEqual(s, s2)
예제 #4
0
 def testNormalize4(self):
     # test multiple interleaved segments
     ss = [(x, x + 100) for x in range(0, 1000, 10)]
     s = SegmentList()
     for start, end in ss:
         s.add(start, end)
     s.normalize()
     self.assertEqual(len(s), 1)
     self.assertEqual(s.sum(), 1090)
     s2 = SegmentList(iter=ss)
     s2.merge(-1)
     self.assertEqual(s, s2)
예제 #5
0
    def testNormalize1b(self):
        '''non-overlapping segments.'''

        ss = [(x, x + 10) for x in range(100, 1100, 100)]
        random.shuffle(ss)
        s = SegmentList()
        for start, end in ss:
            s.add(start, end)
        s.normalize()
        self.assertEqual(len(s), 10)
        self.assertEqual(s.sum(), 100)
        s2 = SegmentList(iter=ss)
        s2.merge(-1)
        self.assertEqual(s, s2)
예제 #6
0
    def testNormalizeEmptySegment(self):
        s = SegmentList(iter=[(0, 0), ])
        s.normalize()
        self.assertEqual(s.isNormalized, 1)
        self.assertEqual(len(s), 0)

        s = SegmentList(iter=[(0, 0), (0, 0)])
        s.normalize()
        self.assertEqual(s.isNormalized, 1)
        self.assertEqual(len(s), 0)

        ss = [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4),
              (0, 5), (0, 6), (0, 7), (0, 8), (0, 9)]
        s = SegmentList(iter=ss)
        s.normalize()
        self.assertEqual(s.isNormalized, 1)
        self.assertEqual(len(s), 1)

        s2 = SegmentList(iter=ss)
        s2.merge(-1)
        self.assertEqual(s, s2)