def test_creation(): assert I.closed(0, 1) == I.AtomicInterval(I.CLOSED, 0, 1, I.CLOSED) assert I.open(0, 1) == I.AtomicInterval(I.OPEN, 0, 1, I.OPEN) assert I.openclosed(0, 1) == I.AtomicInterval(I.OPEN, 0, 1, I.CLOSED) assert I.closedopen(0, 1) == I.AtomicInterval(I.CLOSED, 0, 1, I.OPEN) assert I.closed(-I.inf, I.inf) == I.open(-I.inf, I.inf) assert I.singleton(2) == I.closed(2, 2) assert I.Interval() == I.open(0, 0) assert I.empty() == I.Interval() assert I.closed(3, -3) == I.empty() assert I.openclosed(3, 3) == I.empty() # I.empty() is a singleton assert I.empty() is I.empty() assert I.Interval(I.closed(0, 1).to_atomic()) == I.closed(0, 1) assert I.Interval(I.closed(0, 1)) == I.closed(0, 1) assert I.Interval(I.closed(0, 1).to_atomic(), I.closed(2, 3)) == I.closed(0, 1) | I.closed(2, 3) assert I.Interval(I.closed(0, 1) | I.closed(2, 3)) == I.closed(0, 1) | I.closed(2, 3) with pytest.raises(TypeError): I.Interval(1)
def test_apply(): i = I.closed(0, 1) assert i.apply(lambda s: s) == i assert i.apply(lambda s: (False, -1, 2, False)) == I.open(-1, 2) assert i.apply(lambda s: I.AtomicInterval(False, -1, 2, False)) == I.open( -1, 2) assert i.apply(lambda s: I.open(-1, 2)) == I.open(-1, 2) i = I.closed(0, 1) | I.closed(2, 3) assert i.apply(lambda s: s) == i assert i.apply(lambda s: (False, -1, 2, False)) == I.open(-1, 2) assert i.apply(lambda s: (not s.left, s.lower - 1, s.upper - 1, not s.right )) == I.open(-1, 0) | I.open(1, 2) assert i.apply(lambda s: I.AtomicInterval(False, -1, 2, False)) == I.open( -1, 2) assert i.apply(lambda s: I.open(-1, 2)) == I.open(-1, 2) assert i.apply(lambda s: (s.left, s.lower, s.upper * 2, s.right)) == I.closed(0, 6) assert I.empty().apply(lambda s: (I.CLOSED, 1, 2, I.CLOSED)) == I.closed( 1, 2) with pytest.raises(TypeError): i.apply(lambda s: None) with pytest.raises(TypeError): i.apply(lambda s: 'unsupported')
def test_creation(): assert I.closed(0, 1) == I.AtomicInterval(I.CLOSED, 0, 1, I.CLOSED) assert I.open(0, 1) == I.AtomicInterval(I.OPEN, 0, 1, I.OPEN) assert I.openclosed(0, 1) == I.AtomicInterval(I.OPEN, 0, 1, I.CLOSED) assert I.closedopen(0, 1) == I.AtomicInterval(I.CLOSED, 0, 1, I.OPEN) assert I.closed(-I.inf, I.inf) == I.open(-I.inf, I.inf) with pytest.raises(ValueError): I.closed(1, -1) assert I.singleton(2) == I.closed(2, 2) assert I.Interval() == I.open(0, 0) assert I.empty() == I.Interval()
def test_interval_to_atomic(): intervals = [I.closed(0, 1), I.open(0, 1), I.openclosed(0, 1), I.closedopen(0, 1)] for interval in intervals: assert interval == I.Interval(interval.to_atomic()) assert interval == interval.to_atomic() assert I.closed(0, 1) | I.closed(2, 3) != I.closed(0, 3) assert (I.closed(0, 1) | I.closed(2, 3)).to_atomic() == I.closed(0, 3) assert I.closed(0, 1).to_atomic() == I.closed(0, 1).enclosure() assert (I.closed(0, 1) | I.closed(2, 3)).enclosure() == I.closed(0, 3) assert I.empty().to_atomic() == I.AtomicInterval(False, I.inf, -I.inf, False)