Пример #1
0
 def test_sort_join(self):
     self.assertEqual(
         IntervalSet([
             closed(2, 3),
             closed(2, None),
             closed(None, 1),
             closed(1, 3),
             closed(2, 3),
             closed(-10, None)
         ]), IntervalSet([closed(None, None)]))
     self.assertEqual(
         IntervalSet([
             empty(6),
             closedopen(1, 2),
             empty(0),
             closedopen(2, 3),
             open(4, 5)
         ]),
         IntervalSet([closedopen(1, 3), open(4, 5)]),
     )
Пример #2
0
 def test_contains_operator(self):
     self.assertCallTrue(operator.contains, [
         (closed(0, 0), 0),
         (closed(0, 2), 1),
         (openclosed(None, 0), 0),
         (closedopen(0, None), 0),
         (open(None, None), 0),
     ])
     self.assertCallFalse(operator.contains, [
         (empty(0), 0),
         (closedopen(0, 1), 1),
         (openclosed(0, 1), 0),
         (open(0, 1), 1),
     ])
Пример #3
0
 def test_empty(self):
     self.assertCallTrue(operator.attrgetter("empty"), [
         [empty(0)],
         [closedopen(0, 0)],
         [openclosed(0, 0)],
         [open(0, 0)],
     ])
     self.assertCallFalse(operator.attrgetter("empty"), [
         [single(0)],
         [closed(0, 0)],
         [closed(0, 1)],
         [closedopen(0, 1)],
         [openclosed(0, 1)],
         [open(0, 1)],
     ])
Пример #4
0

@pytest.mark.parametrize('one, other', [
    (closed(0, 0), 0),
    (closed(0, 2), 1),
    (openclosed(None, 0), 0),
    (closedopen(0, None), 0),
    (open(None, None), 0),
])
def test_contained(one, other):
    assert other in one
    assert not (other not in one)


@pytest.mark.parametrize('one, other', [
    (empty(0), 0),
    (closedopen(0, 1), 1),
    (openclosed(0, 1), 0),
    (open(0, 1), 1),
])
def test_not_contained(one, other):
    assert other not in one
    assert not (other in one)


def test_begin_greater_than_end():
    with pytest.raises(ValueError):
        Interval(1, 0)


@pytest.mark.parametrize('one, other, is_strictly_during', [
Пример #5
0
import pytest

from pycroft.helpers.interval import IntervalSet, closed, empty, closedopen, \
    open, openclosed, Interval


@pytest.mark.parametrize('one, other', [
    ([
        closed(2, 3),
        closed(2, None),
        closed(None, 1),
        closed(1, 3),
        closed(2, 3),
        closed(-10, None)
    ], [closed(None, None)]),
    ([empty(6),
      closedopen(1, 2),
      empty(0),
      closedopen(2, 3),
      open(4, 5)], [closedopen(1, 3), open(4, 5)]),
])
def test_constructor(one: list[Interval], other: list[Interval]):
    assert IntervalSet(one) == IntervalSet(other)


@pytest.mark.parametrize('intervals, expected', [
    ([], open(None, None)),
    ([closed(0, 1), open(2, 3)
      ], [open(None, 0), openclosed(1, 2),
          closedopen(3, None)]),
    ([closed(None, 0), closed(1, None)], [open(0, 1)]),