def test_equals(): d = Interval(1, 3) assert d.equals((1, 3)) assert not d.equals(None) assert not d.equals(Interval.closed_open(1, 3)) assert Interval.empty().equals(Interval.empty()) # Empty intervals are always equal assert Interval.open(1, 1).equals(Interval.open(2, 2)) assert Interval.infinite().equals(Interval.infinite())
def test_intersects(): assert Interval.closed(1, 3).intersects(Interval.closed(2, 3)) assert Interval.closed(1, 3).intersects((2, 3)) assert Interval.closed(1, 3).intersects((1, 3)) assert Interval.closed(1, 3).intersects(Interval.open(1, 3)) assert Interval.closed(1, 3).intersects(Interval.closed(3, 4)) assert not Interval.closed(1, 3).intersects(Interval.open(3, 4)) assert not Interval.open(1, 3).intersects(Interval.closed(3, 4)) assert Interval.point(3).intersects(Interval.closed(3, 4)) assert Interval.point(3).intersects(Interval.closed(1, 3)) assert not Interval.point(3).intersects(Interval.open(3, 4)) assert not Interval.point(3).intersects(Interval.open(1, 3)) assert Interval.closed(1, 3).intersects(Interval.closed(0, 1)) assert not Interval.closed(1, 3).intersects(Interval.open(0, 1)) assert not Interval.open(1, 3).intersects(Interval.closed(0, 1)) assert not Interval.closed(1, 3).intersects(Interval.closed(4, 5)) assert not Interval.closed(1, 3).intersects(Interval.closed(-2, 0)) assert not Interval.closed(1, 3).intersects(Interval.empty()) assert Interval.closed(1, 3).intersects(Interval.infinite()) assert not Interval.point(1).intersects(Interval.open_closed(1, 2))
def test_interval_contains_inf(): inf = Interval.infinite() assert inf.contains(math.inf) is True assert inf.contains(-math.inf) is True assert Interval.gte(0).contains(math.inf) is True assert Interval.gte(0).contains(-math.inf) is False assert Interval.lte(0).contains(math.inf) is False assert Interval.lte(0).contains(-math.inf) is True
def __init__(self, y, domain=None): super().__init__(min_step=math.inf) self._value = y if domain is not None: domain = Interval.parse(domain) else: domain = Interval.infinite() self._const_interval = domain
def test_sample_infinite(): f = Constant(1) with pytest.raises(Exception): f.sample_points() with pytest.raises(Exception): f.sample_points(domain=Interval.infinite()) with pytest.raises(Exception): f.sample_points(domain=Interval.gte(0)) with pytest.raises(Exception): f.sample_points(domain=Interval.lte(0))
def test_parse(): d = Interval.parse(Interval(0, 1, start_open=True, end_open=True)) assert d.start == 0 assert d.end == 1 assert d.start_open assert d.end_open d = Interval.parse((0, 1)) assert d.start == 0 assert d.end == 1 assert not d.start_open assert not d.end_open d = Interval.parse(1) assert d.start == 1 assert d.end == 1 assert not d.start_open assert not d.end_open with pytest.raises(Exception): _ = Interval.parse(None) with pytest.raises(Exception): _ = Interval.parse(None, default_inf=False) assert Interval.parse(None, default_inf=True) == Interval.infinite() d = Interval.parse(math.inf) assert math.isinf(d.start) assert math.isinf(d.end) assert d.start > 0 assert d.end > 0 assert not d.is_negative_infinite assert not d.is_positive_infinite d = Interval.parse(-math.inf) assert math.isinf(d.start) assert math.isinf(d.end) assert d.start < 0 assert d.end < 0 assert not d.is_negative_infinite assert not d.is_positive_infinite d = Interval.parse([]) assert d.is_empty
def get_domain(self): return Interval.infinite()
def __init__(self, y_func, domain=None, min_step=MIN_STEP): super().__init__(min_step=min_step) self.y_func = y_func self._domain = Interval.parse(domain) if domain is not None else Interval.infinite()
def end_scan_reset(self): self.end_update(Interval.infinite())
def begin_scan_reset(self): self.reset_scan() self.begin_update(Interval.infinite())