public void testRemoveNoOverlap() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(3, 6)); rangeSet.remove(Range.closedOpen(1, 3)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().allOf(Range.closed(3, 6)).inOrder(); }
public void testRemoveExact() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(3, 6)); rangeSet.remove(Range.closed(3, 6)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).isEmpty(); }
public void testRemovePartFromAboveUpperBound() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(3, 6)); rangeSet.remove(Range.closed(6, 9)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().allOf(Range.closedOpen(3, 6)).inOrder(); }
public void testAddEmpty() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closedOpen(3, 3)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).isEmpty(); ASSERT.that(rangeSet.complement().asRanges()).has().allOf(Range.<Integer>all()).inOrder(); }
public void testRemoveAllFromAboveUpperBound() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(3, 6)); rangeSet.remove(Range.closed(3, 7)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).isEmpty(); }
public void testRemovePartFromBelowLowerBound() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(3, 6)); rangeSet.remove(Range.closed(1, 3)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().allOf(Range.openClosed(3, 6)).inOrder(); }
public void testRemoveAllExtendingBothDirections() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(3, 6)); rangeSet.remove(Range.closed(2, 7)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).isEmpty(); }
public void testRemoveMiddle() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.atMost(6)); rangeSet.remove(Range.closedOpen(3, 4)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().allOf(Range.lessThan(3), Range.closed(4, 6)).inOrder(); ASSERT .that(rangeSet.complement().asRanges()) .has() .allOf(Range.closedOpen(3, 4), Range.greaterThan(6)) .inOrder(); }
public void testRemovePartSharingUpperBound() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(3, 5)); rangeSet.remove(Range.openClosed(3, 5)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().item(Range.singleton(3)); ASSERT .that(rangeSet.complement().asRanges()) .has() .allOf(Range.lessThan(3), Range.greaterThan(3)) .inOrder(); }
public void testExtendBothDirections() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(3, 4)); rangeSet.add(Range.closed(1, 6)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().item(Range.closed(1, 6)); ASSERT .that(rangeSet.complement().asRanges()) .has() .allOf(Range.lessThan(1), Range.greaterThan(6)) .inOrder(); }
public void testIgnoresSmallerSharingUpperBound() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(1, 6)); rangeSet.add(Range.closed(3, 6)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().item(Range.closed(1, 6)); ASSERT .that(rangeSet.complement().asRanges()) .has() .allOf(Range.lessThan(1), Range.greaterThan(6)) .inOrder(); }
public void testMergesConnectedDisjoint() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(1, 4)); rangeSet.add(Range.open(4, 6)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().item(Range.closedOpen(1, 6)); ASSERT .that(rangeSet.complement().asRanges()) .has() .allOf(Range.lessThan(1), Range.atLeast(6)) .inOrder(); }
public void testRemoveEmpty() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closed(1, 6)); rangeSet.remove(Range.closedOpen(3, 3)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().item(Range.closed(1, 6)); ASSERT .that(rangeSet.complement().asRanges()) .has() .allOf(Range.lessThan(1), Range.greaterThan(6)) .inOrder(); }
public void testAllSingleRangesComplementAgainstRemove() { for (Range<Integer> range : QUERY_RANGES) { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(range); TreeRangeSet<Integer> complement = TreeRangeSet.create(); complement.add(Range.<Integer>all()); complement.remove(range); assertEquals(complement, rangeSet.complement()); ASSERT.that(rangeSet.complement().asRanges()).has().allFrom(complement.asRanges()).inOrder(); } }
public void testFillHoleWithOverlap() { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(Range.closedOpen(1, 3)); rangeSet.add(Range.closedOpen(4, 6)); rangeSet.add(Range.closedOpen(2, 5)); testInvariants(rangeSet); ASSERT.that(rangeSet.asRanges()).has().item(Range.closedOpen(1, 6)); ASSERT .that(rangeSet.complement().asRanges()) .has() .allOf(Range.lessThan(1), Range.atLeast(6)) .inOrder(); }
public void testRangesByUpperBound() { for (Range<Integer> range1 : QUERY_RANGES) { for (Range<Integer> range2 : QUERY_RANGES) { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(range1); rangeSet.add(range2); NavigableMap<Cut<Integer>, Range<Integer>> expectedRangesByUpperBound = Maps.newTreeMap(); for (Range<Integer> range : rangeSet.asRanges()) { expectedRangesByUpperBound.put(range.upperBound, range); } testNavigationAgainstExpected( expectedRangesByUpperBound, new TreeRangeSet.RangesByUpperBound<Integer>(rangeSet.rangesByLowerBound), CUTS_TO_TEST); } } }
private static void doPairTest(Range<Integer> a, Range<Integer> b) { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(a); rangeSet.add(b); if (a.isEmpty() && b.isEmpty()) { ASSERT.that(rangeSet.asRanges()).isEmpty(); } else if (a.isEmpty()) { ASSERT.that(rangeSet.asRanges()).has().item(b); } else if (b.isEmpty()) { ASSERT.that(rangeSet.asRanges()).has().item(a); } else if (a.isConnected(b)) { ASSERT.that(rangeSet.asRanges()).has().allOf(a.span(b)).inOrder(); } else { if (a.lowerEndpoint() < b.lowerEndpoint()) { ASSERT.that(rangeSet.asRanges()).has().allOf(a, b).inOrder(); } else { ASSERT.that(rangeSet.asRanges()).has().allOf(b, a).inOrder(); } } }