def testOverlap(self): b = SegmentList(iter=((x, x + 10) for x in range(5, 1000, 100)), normalize = True) b.subtract(self.a) c = [(10, 15), (110, 115), (210, 215), (310, 315), (410, 415), (510, 515), (610, 615), (710, 715), (810, 815), (910, 915)] self.assertEqual(b.asList(), c)
def testFilter(self): b = SegmentList(iter=((x, x + 5) for x in range(500, 2000, 100)), normalize=True) b.filter(self.a) self.assertEqual(b.asList(), [ (500, 505), (600, 605), (700, 705), (800, 805), (900, 905)]) b = SegmentList(iter=((0, 56), )) c = SegmentList(iter=[(0, 50), (75, 125)]) b.filter(c) self.assertEqual(b.asList(), [(0, 56)]) b = SegmentList(iter=((0, 56), )) c = SegmentList(iter=[(0, 10)]) b.filter(c) self.assertEqual(b.asList(), [(0, 56)])
def testSingleSegmentSubtraction(self): a = SegmentList(iter=[(0, 12000)], normalize=True) b = SegmentList(iter=[(0, 10000)], normalize=True) a.subtract(b) self.assertEqual(a.asList(), [(10000, 12000)])
def testCompleteOverlap(self): b = SegmentList(iter=[(0, 1000)], normalize=True) b.subtract(self.a) c = [(10, 100), (110, 200), (210, 300), (310, 400), (410, 500), (510, 600), (610, 700), (710, 800), (810, 900), (910, 1000)] self.assertEqual(b.asList(), c)
def testNoIntersection(self): b = SegmentList(iter=((x, x + 10) for x in range(10, 1000, 100)), normalize = True) b.intersect(self.a) self.assertEqual(b.asList(), []) self.assertEqual(b.isEmpty, True)
def testIntersectionCopy(self): b = SegmentList(clone=self.a) b.intersect(self.a) self.assertEqual(b.asList(), self.a.asList())
def testIntersectionFull(self): b = SegmentList(iter=[(0, 1000)], normalize=True) b.intersect(self.a) self.assertEqual(b.asList(), self.a.asList())
class TestSegmentListIntersection(GatTest): def setUp(self): self.a = SegmentList( iter=((x, x + 10) for x in range(0, 1000, 100)), normalize=True) def testIntersectionFull(self): b = SegmentList(iter=[(0, 1000)], normalize=True) b.intersect(self.a) self.assertEqual(b.asList(), self.a.asList()) def testIntersectionSelf(self): self.a.intersect(self.a) self.assertEqual(self.a.asList(), self.a.asList()) def testIntersectionCopy(self): b = SegmentList(clone=self.a) b.intersect(self.a) self.assertEqual(b.asList(), self.a.asList()) def testNoIntersection(self): b = SegmentList(iter=((x, x + 10) for x in range(10, 1000, 100)), normalize = True) b.intersect(self.a) self.assertEqual(b.asList(), []) self.assertEqual(b.isEmpty, True) def testPartialIntersection(self): b = SegmentList(iter=((x, x + 10) for x in range(5, 1000, 100)), normalize = True) b.intersect(self.a) self.assertEqual(len(b), len(self.a)) self.assertEqual(b.sum(), self.a.sum() / 2) def testOverlap(self): '''test if number of segments intersection is correct.''' b = SegmentList(iter=((x, x + 10) for x in range(5, 1000, 100)), normalize = True) self.assertEqual(self.a.intersectionWithSegments(b), len(b)) self.assertEqual(b.intersectionWithSegments(self.a), len(b)) # no intersection b = SegmentList(iter=((x, x + 10) for x in range(10, 1000, 100)), normalize = True) self.assertEqual(self.a.intersectionWithSegments(b), 0) self.assertEqual(b.intersectionWithSegments(self.a), 0) # double the number of segments in b b = SegmentList(iter=[(x, x + 5) for x in range(0, 1000, 100)] + [(x + 5, x + 10) for x in range(0, 1000, 100)], normalize=True) self.assertEqual(self.a.intersectionWithSegments(b), 10) self.assertEqual(b.intersectionWithSegments(self.a), 20) def testFilter(self): b = SegmentList(iter=((x, x + 5) for x in range(500, 2000, 100)), normalize=True) b.filter(self.a) self.assertEqual(b.asList(), [ (500, 505), (600, 605), (700, 705), (800, 805), (900, 905)]) b = SegmentList(iter=((0, 56), )) c = SegmentList(iter=[(0, 50), (75, 125)]) b.filter(c) self.assertEqual(b.asList(), [(0, 56)]) b = SegmentList(iter=((0, 56), )) c = SegmentList(iter=[(0, 10)]) b.filter(c) self.assertEqual(b.asList(), [(0, 56)])