LongRangeSet.Range#unite fixed

This commit is contained in:
Tagir Valeev
2019-02-06 18:15:28 +07:00
parent 9337a01644
commit 97294f565b
2 changed files with 2 additions and 1 deletions
@@ -1272,7 +1272,7 @@ public abstract class LongRangeSet {
return other.unite(this);
}
if (other instanceof Range) {
if (other.intersects(this) ||
if (other.min() <= max() && min() <= other.max() ||
(other.max() < min() && other.max() + 1 == min()) ||
(other.min() > max() && max() + 1 == other.min())) {
return range(Math.min(min(), other.min()), Math.max(max(), other.max()));
@@ -765,6 +765,7 @@ public class LongRangeSetTest {
assertEquals("{-2..100}: even", modRange(0, 100, 2, 0b1).unite(point(-2)).toString());
assertEquals("{-3, 0..100}", modRange(0, 100, 2, 0b1).unite(point(-3)).toString());
assertEquals("{-4, 0..100}", modRange(0, 100, 2, 0b1).unite(point(-4)).toString());
assertEquals("{Long.MIN_VALUE..9223372036854775744}", range(1, 63).unite(modRange(Long.MIN_VALUE, Long.MAX_VALUE, 64, 0b1)).toString());
}
@Test