@Test
  public void whenCreateRangeSet_thenCreated() {
    final RangeSet<Integer> rangeSet = TreeRangeSet.create();
    rangeSet.add(Range.closed(1, 10));
    rangeSet.add(Range.closed(12, 15));

    assertEquals(2, rangeSet.asRanges().size());

    rangeSet.add(Range.closed(10, 12));
    assertTrue(rangeSet.encloses(Range.closed(1, 15)));
    assertEquals(1, rangeSet.asRanges().size());
  }
 public void testRangeContaining1() {
   RangeSet<Integer> rangeSet = TreeRangeSet.create();
   rangeSet.add(Range.closed(3, 10));
   assertEquals(Range.closed(3, 10), rangeSet.rangeContaining(5));
   assertTrue(rangeSet.contains(5));
   assertNull(rangeSet.rangeContaining(1));
   assertFalse(rangeSet.contains(1));
 }
 private RangeSet<Integer> expectedSubRangeSet(
     RangeSet<Integer> rangeSet, Range<Integer> subRange) {
   RangeSet<Integer> expected = TreeRangeSet.create();
   for (Range<Integer> range : rangeSet.asRanges()) {
     if (range.isConnected(subRange)) {
       expected.add(range.intersection(subRange));
     }
   }
   return expected;
 }
 public void testRangeContaining2() {
   RangeSet<Integer> rangeSet = TreeRangeSet.create();
   rangeSet.add(Range.closed(3, 10));
   rangeSet.remove(Range.open(5, 7));
   assertEquals(Range.closed(3, 5), rangeSet.rangeContaining(5));
   assertTrue(rangeSet.contains(5));
   assertEquals(Range.closed(7, 10), rangeSet.rangeContaining(8));
   assertTrue(rangeSet.contains(8));
   assertNull(rangeSet.rangeContaining(6));
   assertFalse(rangeSet.contains(6));
 }
Example #5
0
 void addWithoutSaving(String jobFullName, int n) {
   synchronized (
       usages) { // XXX why not synchronized (this) like some, though not all, other accesses?
     RangeSet r = usages.get(jobFullName);
     if (r == null) {
       r = new RangeSet();
       usages.put(jobFullName, r);
     }
     r.add(n);
   }
 }
 private RangeSet<Integer> expectedComplement(RangeSet<Integer> rangeSet) {
   RangeSet<Integer> expected = TreeRangeSet.create();
   expected.add(Range.<Integer>all());
   expected.removeAll(rangeSet);
   return expected;
 }