void () { Random r = new Random(1); for (int i = 0; i < 100; i++) { List<LongRangeSet> intervals = new ArrayList<>(); for (int j = 0; j < 20; j++) { int from = r.nextInt(100); intervals.add(range(from, from + r.nextInt(25))); } String start = "i=" + i + ":" + intervals; LongRangeSet union = empty(); for (LongRangeSet interval : intervals) { union = union.join(interval); } while (intervals.size() > 1) { LongRangeSet set1 = intervals.remove(r.nextInt(intervals.size())); LongRangeSet set2 = intervals.remove(r.nextInt(intervals.size())); LongRangeSet result = set1.join(set2); intervals.add(result); } assertEquals(start, union, intervals.get(0)); } }