Exemplo n.º 1
0
 def test_no_overlapping_constraint(self):
     intervals = Intervals(allow_overlapping=False)
     intervals.add(Interval(0, 4))
     with self.assertRaises(IntervalConstraintException):
         intervals.add(Interval(0, 4))
     with self.assertRaises(IntervalConstraintException):
         intervals.add(Interval(-10, 10))
Exemplo n.º 2
0
 def test_interval_relation_disjunct(self):
     self.assertIntervalRelation(Interval(0, 10), Interval(100, 200),
                                 IntervalRelation.Disjunct)
     self.assertIntervalRelation(Interval(100, 200), Interval(0, 10),
                                 IntervalRelation.Disjunct)
     self.assertIntervalRelation(Interval(0, 10), Interval(10, 20),
                                 IntervalRelation.Disjunct)
     self.assertIntervalRelation(Interval(10, 20), Interval(0, 10),
                                 IntervalRelation.Disjunct)
Exemplo n.º 3
0
	def _is_nested_match(self, offset, length):
		if self._args.extract_nested:
			# Completely disregard if we've already captured this.
			return False
		interval = Interval.begin_length(offset, length)
		if self._matches.fully_contained_in_subinterval(interval):
			# We already have this match.
			return True
		else:
			self._matches.add(interval)
			return False
Exemplo n.º 4
0
 def test_interval_relation_by_enumeration(self):
     for start1 in range(-5, 5):
         for len1 in range(1, 4):
             intvl1 = Interval(start1, start1 + len1)
             members1 = set(intvl1.enumerate_members())
             for start2 in range(-5, 5):
                 for len2 in range(1, 4):
                     intvl2 = Interval(start2, start2 + len2)
                     members2 = set(intvl2.enumerate_members())
                     intersect = members1 & members2
                     if members1 == members2:
                         expect_relation = IntervalRelation.Identical
                     elif len(intersect) == 0:
                         expect_relation = IntervalRelation.Disjunct
                     elif intersect == members1:
                         expect_relation = IntervalRelation.Contained
                     elif intersect == members2:
                         expect_relation = IntervalRelation.Container
                     else:
                         expect_relation = IntervalRelation.Overlapping
                     self.assertIntervalRelation(intvl1, intvl2,
                                                 expect_relation)
Exemplo n.º 5
0
    def test_interval_relation_overlapping(self):
        self.assertIntervalRelation(Interval(0, 10), Interval(1, 11),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(1, 11), Interval(0, 10),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(0, 10), Interval(5, 200),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(0, 10), Interval(-100, 5),
                                    IntervalRelation.Overlapping)

        self.assertIntervalRelation(Interval(0, 10), Interval(-100, -20),
                                    IntervalRelation.Disjunct)
        self.assertIntervalRelation(Interval(0, 10), Interval(-100, 0),
                                    IntervalRelation.Disjunct)
        self.assertIntervalRelation(Interval(0, 10), Interval(-100, 1),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(0, 10), Interval(-100, 5),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(0, 10), Interval(-100, 9),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(0, 10), Interval(-100, 10),
                                    IntervalRelation.Contained)
        self.assertIntervalRelation(Interval(0, 10), Interval(-100, 11),
                                    IntervalRelation.Contained)
        self.assertIntervalRelation(Interval(0, 10), Interval(-100, 1000),
                                    IntervalRelation.Contained)

        self.assertIntervalRelation(Interval(0, 10), Interval(20, 100),
                                    IntervalRelation.Disjunct)
        self.assertIntervalRelation(Interval(0, 10), Interval(10, 100),
                                    IntervalRelation.Disjunct)
        self.assertIntervalRelation(Interval(0, 10), Interval(9, 100),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(0, 10), Interval(5, 100),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(0, 10), Interval(1, 100),
                                    IntervalRelation.Overlapping)
        self.assertIntervalRelation(Interval(0, 10), Interval(0, 100),
                                    IntervalRelation.Contained)
        self.assertIntervalRelation(Interval(0, 10), Interval(-1, 100),
                                    IntervalRelation.Contained)
        self.assertIntervalRelation(Interval(0, 10), Interval(-1000, 100),
                                    IntervalRelation.Contained)
Exemplo n.º 6
0
 def test_interval_relation_identical(self):
     self.assertIntervalRelation(Interval(0, 10), Interval(0, 10),
                                 IntervalRelation.Identical)
     self.assertIntervalRelation(Interval(20, 100), Interval(20, 100),
                                 IntervalRelation.Identical)
Exemplo n.º 7
0
 def test_interval_comparison(self):
     self.assertLess(Interval(0, 1), Interval(0, 2))
     self.assertLess(Interval(0, 1), Interval(1, 2))
     self.assertEqual(Interval(0, 10), Interval(0, 10))
     self.assertEqual(Interval(10, 20), Interval(10, 20))
     self.assertNotEqual(Interval(0, 1), Interval(0, 2))
Exemplo n.º 8
0
 def test_interval_fully_contained_subinterval(self):
     intervals = Intervals()
     intervals.add(Interval(100, 1285))
     new = Interval(287, 407)
     self.assertTrue(intervals.fully_contained_in_subinterval(new))
Exemplo n.º 9
0
 def test_no_identical_constraint(self):
     intervals = Intervals(allow_identical=False)
     intervals.add(Interval(0, 4))
     with self.assertRaises(IntervalConstraintException):
         intervals.add(Interval(0, 4))
     intervals.add(Interval(-10, 10))
Exemplo n.º 10
0
 def test_no_constraints(self):
     intervals = Intervals()
     intervals.add(Interval(0, 4))
     intervals.add(Interval(0, 4))
     intervals.add(Interval(-10, 10))
Exemplo n.º 11
0
    def test_fully_contained(self):
        intervals = Intervals()
        intervals.add(Interval(0, 4))
        intervals.add(Interval(3, 6))

        self.assertTrue(
            intervals.fully_contained_in_subinterval(Interval(1, 2)))
        self.assertTrue(
            intervals.fully_contained_in_subinterval(Interval(1, 4)))
        self.assertTrue(
            intervals.fully_contained_in_subinterval(Interval(0, 4)))
        self.assertTrue(
            intervals.fully_contained_in_subinterval(Interval(0, 3)))
        self.assertTrue(
            intervals.fully_contained_in_subinterval(Interval(3, 4)))
        self.assertTrue(
            intervals.fully_contained_in_subinterval(Interval(3, 6)))
        self.assertTrue(
            intervals.fully_contained_in_subinterval(Interval(4, 5)))
        self.assertFalse(
            intervals.fully_contained_in_subinterval(Interval(0, 10)))
        self.assertFalse(
            intervals.fully_contained_in_subinterval(Interval(0, 5)))
        self.assertFalse(
            intervals.fully_contained_in_subinterval(Interval(-1, 4)))
        self.assertFalse(
            intervals.fully_contained_in_subinterval(Interval(3, 1000)))
        self.assertFalse(
            intervals.fully_contained_in_subinterval(Interval(-100, 1000)))
Exemplo n.º 12
0
    def test_intervals_interacting(self):
        intervals = Intervals()
        intervals.add(Interval(0, 4))
        intervals.add(Interval(3, 6))

        self.assertEqual(list(intervals.find_interacting(Interval(-10, -5))),
                         [])
        self.assertEqual(list(intervals.find_interacting(Interval(-10, 0))),
                         [])
        self.assertEqual(list(intervals.find_interacting(Interval(-10, 1))),
                         [intervals[0]])
        self.assertEqual(list(intervals.find_interacting(Interval(-10, 3))),
                         [intervals[0]])
        self.assertEqual(list(intervals.find_interacting(Interval(-10, 4))),
                         [intervals[0], intervals[1]])
        self.assertEqual(list(intervals.find_interacting(Interval(-10, 5))),
                         [intervals[0], intervals[1]])
        self.assertEqual(list(intervals.find_interacting(Interval(-10, 10))),
                         [intervals[0], intervals[1]])
        self.assertEqual(list(intervals.find_interacting(Interval(0, 10))),
                         [intervals[0], intervals[1]])
        self.assertEqual(list(intervals.find_interacting(Interval(1, 10))),
                         [intervals[0], intervals[1]])
        self.assertEqual(list(intervals.find_interacting(Interval(3, 10))),
                         [intervals[0], intervals[1]])
        self.assertEqual(list(intervals.find_interacting(Interval(4, 10))),
                         [intervals[1]])
        self.assertEqual(list(intervals.find_interacting(Interval(5, 10))),
                         [intervals[1]])
        self.assertEqual(list(intervals.find_interacting(Interval(6, 10))), [])
        self.assertEqual(list(intervals.find_interacting(Interval(2, 5))),
                         [intervals[0], intervals[1]])
Exemplo n.º 13
0
 def test_intervals_enumerate(self):
     intervals = Intervals()
     intervals.add(Interval(3, 5))
     intervals.add(Interval(0, 4))
     self.assertEqual(list(intervals.enumerate_members()),
                      [0, 1, 2, 3, 3, 4])
Exemplo n.º 14
0
 def test_interval_enumeration(self):
     self.assertEqual(list(Interval(0, 5).enumerate_members()),
                      [0, 1, 2, 3, 4])
     self.assertEqual(list(Interval(-3, 3).enumerate_members()),
                      [-3, -2, -1, 0, 1, 2])