Example #1
0
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
Example #2
0
def test_extensions():
    d = Interval(1, 3)
    assert d.get_lte().equals(Interval.lte(3))
    assert d.get_gte().equals(Interval.gte(1))
    assert d.get_lt().equals(Interval.lt(1))
    assert d.get_gt().equals(Interval.gt(3))

    d = Interval.open(1, 3)
    assert d.get_lte().equals(Interval.lt(3))
    assert d.get_gte().equals(Interval.gt(1))
    assert d.get_lt().equals(Interval.lte(1))
    assert d.get_gt().equals(Interval.gte(3))

    d = Interval.empty()
    assert d.get_lte().is_empty
    assert d.get_gte().is_empty
    assert d.get_lt().is_empty
    assert d.get_gt().is_empty
Example #3
0
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))
Example #4
0
def test_infinite():
    assert Interval.gte(math.inf).is_empty is True
    assert Interval.gte(-math.inf).is_empty is False
    assert Interval.lte(math.inf).is_empty is False
    assert Interval.lte(-math.inf).is_empty is True