Package org.antlr.misc

Examples of org.antlr.misc.IntervalSet


    String result = (s.complement(vocabulary)).toString();
    assertEquals(result, expecting);
  }

    @Test public void testNotSetFragmentedVocabulary() throws Exception {
        IntervalSet vocabulary = IntervalSet.of(1,255);
        vocabulary.add(1000,2000);
        vocabulary.add(9999);
        IntervalSet s = IntervalSet.of(50,60);
        s.add(3);
        s.add(250,300);
        s.add(10000); // this is outside range of vocab and should be ignored
        String expecting = "{1..2, 4..49, 61..249, 1000..2000, 9999}";
        String result = (s.complement(vocabulary)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here


        String result = (s.complement(vocabulary)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfCompletelyContainedRange() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(12,15);
        String expecting = "{10..11, 16..20}";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfOverlappingRangeFromLeft() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(5,11);
        String expecting = "12..20";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);

        IntervalSet s3 = IntervalSet.of(5,10);
        expecting = "11..20";
        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfOverlappingRangeFromRight() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(15,25);
        String expecting = "10..14";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);

        IntervalSet s3 = IntervalSet.of(20,25);
        expecting = "10..19";
        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfCompletelyCoveredRange() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(1,25);
        String expecting = "{}";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);
    }

    @Test public void testSubtractOfRangeSpanningMultipleRanges() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        s.add(30,40);
        s.add(50,60); // s has 3 ranges now: 10..20, 30..40, 50..60
        IntervalSet s2 = IntervalSet.of(5,55); // covers one and touches 2nd range
        String expecting = "56..60";
        String result = (s.subtract(s2)).toString();
        assertEquals(result, expecting);

        IntervalSet s3 = IntervalSet.of(15,55); // touches both
        expecting = "{10..14, 56..60}";
        result = (s.subtract(s3)).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

  /** The following was broken:
     {0..113, 115..65534}-{0..115, 117..65534}=116..65534
   */
  @Test public void testSubtractOfWackyRange() throws Exception {
    IntervalSet s = IntervalSet.of(0,113);
    s.add(115,200);
    IntervalSet s2 = IntervalSet.of(0,115);
    s2.add(117,200);
    String expecting = "116";
    String result = (s.subtract(s2)).toString();
    assertEquals(result, expecting);
  }
View Full Code Here

    String result = (s.subtract(s2)).toString();
    assertEquals(result, expecting);
  }

    @Test public void testSimpleEquals() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        IntervalSet s2 = IntervalSet.of(10,20);
        Boolean expecting = true;
        Boolean result = s.equals(s2);
        assertEquals(result, expecting);

        IntervalSet s3 = IntervalSet.of(15,55);
        expecting = false;
        result = s.equals(s3);
        assertEquals(result, expecting);
    }
View Full Code Here

        result = s.equals(s3);
        assertEquals(result, expecting);
    }

    @Test public void testEquals() throws Exception {
        IntervalSet s = IntervalSet.of(10,20);
        s.add(2);
        s.add(499,501);
        IntervalSet s2 = IntervalSet.of(10,20);
        s2.add(2);
        s2.add(499,501);
        Boolean expecting = true;
        Boolean result = s.equals(s2);
        assertEquals(result, expecting);

        IntervalSet s3 = IntervalSet.of(10,20);
        s3.add(2);
        expecting = false;
        result = s.equals(s3);
        assertEquals(result, expecting);
    }
View Full Code Here

        result = s.equals(s3);
        assertEquals(result, expecting);
    }

    @Test public void testSingleElementMinusDisjointSet() throws Exception {
        IntervalSet s = IntervalSet.of(15,15);
        IntervalSet s2 = IntervalSet.of(1,5);
        s2.add(10,20);
        String expecting = "{}"; // 15 - {1..5, 10..20} = {}
        String result = s.subtract(s2).toString();
        assertEquals(result, expecting);
    }
View Full Code Here

TOP

Related Classes of org.antlr.misc.IntervalSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.