示例#1
0
def test_creation_errors():

    with pytest.raises(
            ArithmeticError,
            match=
            "`width` of interval must number higher or at least equal to 0."):
        IntervalFactory.midpoint_width(0, -1)

    with pytest.raises(
            ValueError,
            match=
            "The interval is invalid. `minimum` must be lower or equal to `maximum`"
    ):
        IntervalFactory.infimum_supremum(3, 1)

    with pytest.raises(
            ValueError,
            match="`precision` should be value from range `0` to `15`"):
        Interval(1, 3, precision=-1)
        Interval(1, 3, precision=16)

    with pytest.warns(UserWarning, match="Using default value of precision"):
        Interval(1, 3, precision="pre")

    with pytest.raises(ValueError,
                       match="Cannot parse Interval from this definition"):
        IntervalFactory.parse_string("[1, 2.5, 5]")

    with pytest.raises(ValueError,
                       match="Cannot parse Interval from this definition"):
        IntervalFactory.parse_string("[]")

    with pytest.raises(ValueError,
                       match="Cannot parse Interval from this definition"):
        IntervalFactory.parse_string("[\"aa\", \"b\"]")
示例#2
0
def test_creation():

    assert isinstance(IntervalFactory.infimum_supremum(1, 3), Interval)

    assert isinstance(IntervalFactory.infimum_supremum(2, 5), Interval)

    assert isinstance(IntervalFactory.infimum_supremum(4, 7), Interval)

    assert isinstance(IntervalFactory.infimum_supremum(-2, 3), Interval)

    assert isinstance(IntervalFactory.infimum_supremum(-1, 1), Interval)

    assert isinstance(IntervalFactory.empty(), Interval)

    interval = IntervalFactory.two_values(1.0000000000001,
                                          3.000000009,
                                          precision=2)

    assert interval == IntervalFactory.two_values(1, 3, precision=2)

    interval = IntervalFactory.parse_string("[1, 2.5]")

    assert interval.min == 1
    assert interval.max == 2.5