def test_simple_interval(self): int_interval = Interval(5, 9) assert int_interval.contains(7) assert int_interval.contains(6) assert Interval.intersects(int_interval, Interval(7, 10)) assert int_interval.intersection(Interval(7, 10)) == Interval( 7, 9).intersection(int_interval)
def query_interval(self, interval, answer): """ Query for all intervals that intersect a given interval. Args: interval: The Interval to check intersection against answer: The return list of IntervalInfo's Returns: The answer list of IntervalInfo's """ if Interval.intersects(self.interval, interval): answer.append(IntervalInfo(self.interval, self.value, self)) if self.left != self.nil and (self.left.min <= interval.upper and self.left.max > interval.lower): self.left.query_interval(interval, answer) if self.right != self.nil and (self.right.min <= interval.upper and self.right.max > interval.lower): self.right.query_interval(interval, answer) return answer