def test_intervals_union(self): nullx = NullInterval(x) # All nulls assert nullx.union(nullx) == nullx ix = Interval(x, -2, 2) # Mixed nulls and defined on the same dimension assert nullx.union(ix) == ix assert ix.union(ix) == ix assert ix.union(nullx) == ix ix2 = Interval(x, 1, 4) ix3 = Interval(x, -3, 6) # All defined overlapping assert ix.union(ix2) == Interval(x, -2, 4) assert ix.union(ix3) == ix3 assert ix2.union(ix3) == ix3 ix4 = Interval(x, 4, 8) ix5 = Interval(x, -3, -3) ix6 = Interval(x, -10, -3) nully = NullInterval(y) iy = Interval(y, -2, 2) # Mixed disjoint (note: IntervalGroup input order is relevant) assert ix.union(ix4) == IntervalGroup([ix, ix4]) assert ix.union(ix5) == Interval(x, -3, 2) assert ix6.union(ix) == IntervalGroup([ix6, ix]) assert ix.union(nully) == IntervalGroup([ix, nully]) assert ix.union(iy) == IntervalGroup([ix, iy]) assert iy.union(ix) == IntervalGroup([iy, ix])
def test_intervals_union(self): nullx = NullInterval(x) # All nulls assert nullx.union(nullx) == nullx ix = Interval(x, -2, 2) # Mixed nulls and defined on the same dimension assert nullx.union(ix) == ix assert ix.union(ix) == ix assert ix.union(nullx) == ix ix2 = Interval(x, 1, 4) ix3 = Interval(x, -3, 6) # All defined overlapping assert ix.union(ix2) == Interval(x, -2, 4) assert ix.union(ix3) == ix3 assert ix2.union(ix3) == ix3 ix4 = Interval(x, 4, 8) ix5 = Interval(x, -3, -3) ix6 = Interval(x, -10, -3) nully = NullInterval(y) iy = Interval(y, -2, 2) # Mixed disjoint (note: IntervalGroup input order is relevant) assert ix.union(ix4) == IntervalGroup([ix, ix4]) assert ix.union(ix5) == Interval(x, -3, 2) assert ix6.union(ix) == IntervalGroup([ix6, ix]) assert ix.union(nully) == IntervalGroup([ix, nully]) assert ix.union(iy) == IntervalGroup([ix, iy]) assert iy.union(ix) == IntervalGroup([iy, ix])
def test_intervals_union(self, x, y): nullx = NullInterval(x) # All nulls assert nullx.union(nullx) == nullx ix = Interval(x, -2, 2) # Mixed nulls and defined assert nullx.union(ix) == ix assert ix.union(ix) == ix assert ix.union(nullx) == ix ix2 = Interval(x, 1, 4) ix3 = Interval(x, -3, 6) assert ix.union(ix2) == Interval(x, -2, 4) assert ix.union(ix3) == ix3 assert ix2.union(ix3) == ix3 ix4 = Interval(x, 4, 8) ix5 = Interval(x, -3, -3) ix6 = Interval(x, -10, -3) nully = NullInterval(y) iy = Interval(y, -2, 2) assert ix.union(ix4) == Interval(x, -2, 8) assert ix.union(ix5) == Interval(x, -3, 2) assert ix6.union(ix) == Interval(x, -10, 2) # The union of non-compatible Intervals isn't possible, and an exception # is expected ixs1 = Interval(x, -2, 2, stamp=1) for i, j in [(ix, nully), (ix, iy), (iy, ix), (ix, ixs1), (ixs1, ix)]: try: i.union(j) assert False # Shouldn't arrive here except ValueError: assert True except: # No other types of exception expected assert False # Mixed symbolic and non-symbolic c = Constant(name='c') ix7 = Interval(x, c, c + 4) ix8 = Interval(x, c - 1, c + 5) assert ix7.union(ix8) == Interval(x, c - 1, c + 5) assert ix8.union(ix7) == Interval(x, c - 1, c + 5) # Symbolic with properties s = Scalar(name='s', nonnegative=True) ix9 = Interval(x, s - 2, s + 2) ix10 = Interval(x, s - 1, s + 1) assert ix.union(ix9) == Interval(x, -2, s + 2) assert ix9.union(ix) == Interval(x, -2, s + 2) assert ix9.union(ix10) == ix9 assert ix10.union(ix9) == ix9
def test_intervals_union(self): nullx = NullInterval(x) # All nulls assert nullx.union(nullx) == nullx ix = Interval(x, -2, 2) # Mixed nulls and defined assert nullx.union(ix) == ix assert ix.union(ix) == ix assert ix.union(nullx) == ix ix2 = Interval(x, 1, 4) ix3 = Interval(x, -3, 6) assert ix.union(ix2) == Interval(x, -2, 4) assert ix.union(ix3) == ix3 assert ix2.union(ix3) == ix3 ix4 = Interval(x, 4, 8) ix5 = Interval(x, -3, -3) ix6 = Interval(x, -10, -3) nully = NullInterval(y) iy = Interval(y, -2, 2) assert ix.union(ix4) == Interval(x, -2, 8) assert ix.union(ix5) == Interval(x, -3, 2) assert ix6.union(ix) == Interval(x, -10, 2) assert ix.union(nully) == IntervalGroup([ix, nully]) assert ix.union(iy) == IntervalGroup([ix, iy]) assert iy.union(ix) == IntervalGroup([iy, ix]) # Mixed symbolic and non-symbolic c = Constant(name='c') ix7 = Interval(x, c, c + 4) ix8 = Interval(x, c - 1, c + 5) assert ix7.union(ix8) == Interval(x, c - 1, c + 5) assert ix8.union(ix7) == Interval(x, c - 1, c + 5) # Symbolic with properties s = Scalar(name='s', nonnegative=True) ix9 = Interval(x, s - 2, s + 2) ix10 = Interval(x, s - 1, s + 1) assert ix.union(ix9) == Interval(x, -2, s + 2) assert ix9.union(ix) == Interval(x, -2, s + 2) assert ix9.union(ix10) == ix9 assert ix10.union(ix9) == ix9