void () { Random r = new Random(1); LongRangeSet[] data = r.ints(1000, 0, 1000) .mapToObj(x -> range(x, x + r.nextInt((x % 20) * 100 + 1))).toArray(LongRangeSet[]::new); for (int i = 0; i < 2000; i++) { int idx = r.nextInt(data.length); LongRangeSet left = data[idx]; LongRangeSet right = data[r.nextInt(data.length)]; LongRangeSet lDiff = left.subtract(right); LongRangeSet rDiff = right.subtract(left); LongRangeSet intersection = left.meet(right); String message = left + " & " + right + " = " + intersection; assertEquals(message, intersection, right.meet(left)); if (!intersection.isEmpty()) { assertTrue(message, intersection.min() >= Math.max(left.min(), right.min())); assertTrue(message, intersection.max() <= Math.min(left.max(), right.max())); } assertEquals(message, intersection, right.subtract(fromTypeStrict(PsiTypes.longType()).subtract(left))); assertEquals(message, intersection, left.subtract(fromTypeStrict(PsiTypes.longType()).subtract(right))); intersection.stream().limit(1000).forEach(e -> { assertTrue(left.contains(e)); assertTrue(right.contains(e)); }); lDiff.stream().limit(1000).forEach(e -> { assertTrue(left.contains(e)); assertFalse(right.contains(e)); }); rDiff.stream().limit(1000).forEach(e -> { assertFalse(left.contains(e)); assertTrue(right.contains(e)); }); switch (r.nextInt(3)) { case 0 -> data[idx] = lDiff; case 1 -> data[idx] = rDiff; case 2 -> data[idx] = intersection; } } }