Example #1
0
 def test_and_operator_for_half_open_intervals_with_empty_results(
     self,
     interval1,
     interval2,
     empty
 ):
     assert (
         IntInterval.from_string(interval1) &
         IntInterval.from_string(interval2)
     ).empty == empty
Example #2
0
 def test_and_operator_with_half_open_intervals(
     self,
     interval1,
     interval2,
     result
 ):
     assert (
         IntInterval.from_string(interval1) &
         IntInterval.from_string(interval2) ==
         IntInterval(result)
     )
Example #3
0
 def test_or_operator(
     self,
     interval1,
     interval2,
     result
 ):
     assert (
         IntInterval.from_string(interval1) |
         IntInterval.from_string(interval2) ==
         result
     )
 def test_at_most(self):
     interval = IntInterval.at_most(10, step=2)
     assert interval.lower == -inf
     assert interval.upper == 10
     assert not interval.lower_inc
     assert interval.upper_inc
     assert interval.step == 2
 def test_all(self):
     interval = IntInterval.all(step=2)
     assert interval.lower == -inf
     assert interval.upper == inf
     assert not interval.lower_inc
     assert not interval.upper_inc
     assert interval.step == 2
 def test_less_than(self):
     interval = IntInterval.less_than(10, step=2)
     assert interval.lower == -inf
     assert interval.upper == 10
     assert not interval.lower_inc
     assert not interval.upper_inc
     assert interval.step == 2
 def test_greater_than(self):
     interval = IntInterval.greater_than(10, step=2)
     assert interval.lower == 10
     assert interval.upper == inf
     assert not interval.lower_inc
     assert not interval.upper_inc
     assert interval.step == 2
 def test_closed_open(self):
     interval = IntInterval.closed_open(10, 14, step=2)
     assert interval.lower == 10
     assert interval.upper == 14
     assert interval.lower_inc
     assert not interval.upper_inc
     assert interval.step == 2
Example #9
0
    def start_flow(self, t):
        """
        Only flow after the specified t will actually be transferred from the source account to dest.
        """
        if self._flow_enabled:
            raise PipeException("Flow already started")

        if t < self._last_flushed_t:
            raise PipeException("Time travel not supported yet")

        if not self._last_stopped_t == None:
            self._blackouts.append(IntInterval.closed_open(self._last_stopped_t, t))

        self._last_flushed_t = t
        self._flow_enabled = True
Example #10
0
 def test_supports_strings_with_bounds(self):
     interval = IntInterval.from_string('[1, 3]')
     assert interval.lower == 1
     assert interval.upper == 3
     assert interval.lower_inc
     assert interval.upper_inc
Example #11
0
 def test_supports_strings_with_spaces(self):
     interval = IntInterval.from_string('1 - 3')
     assert interval.lower == 1
     assert interval.upper == 3
     assert interval.lower_inc
     assert interval.upper_inc
Example #12
0
 def test_hyphen_format(self, number_range, lower, upper):
     interval = IntInterval.from_string(number_range)
     assert interval.lower == lower
     assert interval.upper == upper
Example #13
0
 def test_supports_exact_ranges_as_strings(self):
     interval = IntInterval.from_string('3')
     assert interval.lower == 3
     assert interval.upper == 3
     assert interval.lower_inc
     assert interval.upper_inc
Example #14
0
 def test_intersection(self, first, second, intersection):
     assert (
         IntInterval.from_string(first) &
         IntInterval.from_string(second)
     ) == IntInterval.from_string(intersection)
from pytest import mark

from intervals import IntInterval


@mark.parametrize(('interval', 'string'), (
    (IntInterval((1, 3)), '2'),
    (IntInterval([1, 1]), '1'),
    (IntInterval([1, 3]), '1 - 3'),
    (IntInterval.from_string('(1, 5]'), '2 - 5'),
    (IntInterval.from_string('[1,]'), '1 -')
))
def test_hyphenized(interval, string):
    assert interval.hyphenized == string
Example #16
0
 def test_or_operator_with_illegal_arguments(self, interval1, interval2):
     with raises(IllegalArgument):
         (
             IntInterval.from_string(interval1) |
             IntInterval.from_string(interval2)
         )
Example #17
0
 def test_eq_operator(self, interval, interval2):
     assert (
         IntInterval.from_string(interval) ==
         IntInterval.from_string(interval2)
     )
Example #18
0
def test_int_with_empty_interval(number_range):
    with raises(TypeError):
        int(IntInterval.from_string(number_range))
Example #19
0
 def test_step_argument_for_from_string(self):
     interval = IntInterval.from_string('[2,)', step=2)
     assert interval.lower == 2
     assert interval.upper == inf
     assert interval.step == 2
 def test_open(self):
     interval = IntInterval.open(12, 14, step=2)
     assert interval.lower == 12
     assert interval.upper == 14
     assert interval.is_open
     assert interval.step == 2
 def test_closed(self):
     interval = IntInterval.closed(10, 11, step=2)
     assert interval.lower == 10
     assert interval.upper == 12
     assert interval.is_closed
     assert interval.step == 2
Example #22
0
 def test_empty_string_as_lower_bound(self):
     interval = IntInterval.from_string('[,1)')
     assert interval.lower == -inf
     assert interval.upper == 1
     assert interval.lower_inc
     assert not interval.upper_inc
Example #23
0
@mark.parametrize(('interval', 'string'), (
    ((1, 3), '(1, 3)'),
    ([1, 1], '[1, 1]'),
    ([1, inf], '[1,]')
))
def test_str_representation(interval, string):
    assert str(IntInterval(interval)) == string


@mark.parametrize(
    ('number_range', 'empty'),
    (
        (IntInterval((2, 3)), True),
        (IntInterval([2, 3]), False),
        (IntInterval([2, 2]), False),
        (IntInterval.from_string('[2, 2)'), True),
        (IntInterval.from_string('(2, 2]'), True),
        (IntInterval.from_string('[2, 3)'), False),
        (IntInterval((2, 10)), False),
    )
)
def test_bool(number_range, empty):
    assert bool(IntInterval(number_range)) != empty


@mark.parametrize(
    ('number_range', 'coerced_value'),
    (
        ([5, 5], 5),
        ([2, 2], 2),
    )