Example #1
0
        public void TestSingleElement() /*throws Exception*/
        {
            IntervalSet s         = IntervalSet.Of(99);
            string      expecting = "99";

            Assert.AreEqual(s.ToString(), expecting);
        }
Example #2
0
        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);
        }
Example #3
0
        public void TestRangeAndIsolatedElement() /*throws Exception*/
        {
            IntervalSet s         = IntervalSet.Of('a', 'z');
            IntervalSet s2        = IntervalSet.Of('d');
            string      expecting = "100";
            string      result    = (s.And(s2)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #4
0
        public void TestEmptyIntersection() /*throws Exception*/
        {
            IntervalSet s         = IntervalSet.Of('a', 'z');
            IntervalSet s2        = IntervalSet.Of('0', '9');
            string      expecting = "{}";
            string      result    = (s.And(s2)).ToString();

            assertEquals(result, expecting);
        }
Example #5
0
        public void TestNotEqualSet() /*throws Exception*/
        {
            IntervalSet vocabulary = IntervalSet.Of(1, 1000);
            IntervalSet s          = IntervalSet.Of(1, 1000);
            string      expecting  = "{}";
            string      result     = (s.Complement(vocabulary)).ToString();

            assertEquals(result, expecting);
        }
Example #6
0
        public void TestNotSetEdgeElement() /*throws Exception*/
        {
            IntervalSet vocabulary = IntervalSet.Of(1, 2);
            IntervalSet s          = IntervalSet.Of(1);
            string      expecting  = "2";
            string      result     = (s.Complement(vocabulary)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #7
0
        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();

            Assert.AreEqual(result, expecting);
        }
 private void HandleSetElementCharRange(IIntSet elements, GrammarAST c1, GrammarAST c2)
 {
     if (grammar.type == GrammarType.Lexer)
     {
         int a = Grammar.GetCharValueFromGrammarCharLiteral(c1.Text);
         int b = Grammar.GetCharValueFromGrammarCharLiteral(c2.Text);
         elements.AddAll(IntervalSet.Of(a, b));
     }
 }
Example #9
0
        public void TestEmptyIntersectionSingleElements() /*throws Exception*/
        {
            IntervalSet s         = IntervalSet.Of('a');
            IntervalSet s2        = IntervalSet.Of('d');
            string      expecting = "{}";
            string      result    = (s.And(s2)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #10
0
        public void TestSimpleAnd() /*throws Exception*/
        {
            IntervalSet s         = IntervalSet.Of(10, 20);
            IntervalSet s2        = IntervalSet.Of(13, 15);
            string      expecting = "13..15";
            string      result    = (s.And(s2)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #11
0
        public void TestComplement2() /*throws Exception*/
        {
            IntervalSet s         = IntervalSet.Of(100, 101);
            Interval    s2        = Interval.FromBounds(100, 102);
            string      expecting = "102";
            string      result    = (s.Complement(s2)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #12
0
        public void TestComplement3() /*throws Exception*/
        {
            IntervalSet s = IntervalSet.Of(1, 96);

            s.Add(99, Label.MAX_CHAR_VALUE);
            string expecting = "97..98";
            string result    = (s.Complement(1, Label.MAX_CHAR_VALUE)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #13
0
        public void TestMergeOfRangesAndSingleValuesReverse() /*throws Exception*/
        {
            IntervalSet s = IntervalSet.Of(43, 65534);

            s.Add(42);
            s.Add(0, 41);
            string expecting = "0..65534";
            string result    = s.ToString();

            Assert.AreEqual(result, expecting);
        }
Example #14
0
        public void TestSize() /*throws Exception*/
        {
            IntervalSet s = IntervalSet.Of(20, 30);

            s.Add(50, 55);
            s.Add(5, 19);
            string expecting = "32";
            string result    = s.Count.ToString();

            Assert.AreEqual(result, expecting);
        }
Example #15
0
        public void TestComplement() /*throws Exception*/
        {
            IntervalSet s = IntervalSet.Of(100, 100);

            s.Add(101, 101);
            IntervalSet s2        = IntervalSet.Of(100, 102);
            string      expecting = "102";
            string      result    = (s.Complement(s2)).ToString();

            assertEquals(result, expecting);
        }
Example #16
0
        public void TestIsolatedElements() /*throws Exception*/
        {
            IntervalSet s = new IntervalSet();

            s.Add(1);
            s.Add('z');
            s.Add('\uFFF0');
            string expecting = "{1, 122, 65520}";

            Assert.AreEqual(s.ToString(), expecting);
        }
Example #17
0
        public void TestMixedRangesAndElements() /*throws Exception*/
        {
            IntervalSet s = new IntervalSet();

            s.Add(1);
            s.Add('a', 'z');
            s.Add('0', '9');
            string expecting = "{1, 48..57, 97..122}";

            Assert.AreEqual(s.ToString(), expecting);
        }
Example #18
0
        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();

            Assert.AreEqual(result, expecting);
        }
Example #19
0
        public void TestNotSingleElement() /*throws Exception*/
        {
            IntervalSet vocabulary = IntervalSet.Of(1, 1000);

            vocabulary.Add(2000, 3000);
            IntervalSet s         = IntervalSet.Of(50, 50);
            string      expecting = "{1..49, 51..1000, 2000..3000}";
            string      result    = (s.Complement(vocabulary)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #20
0
        public void TestMergeWithDoubleOverlap() /*throws Exception*/
        {
            IntervalSet s = IntervalSet.Of(1, 10);

            s.Add(20, 30);
            s.Add(5, 25);   // overlaps two!
            string expecting = "1..30";
            string result    = s.ToString();

            Assert.AreEqual(result, expecting);
        }
Example #21
0
        public void TestIntersectionWithTwoContainedElementsReversed() /*throws Exception*/
        {
            IntervalSet s  = IntervalSet.Of(10, 20);
            IntervalSet s2 = IntervalSet.Of(2, 2);

            s2.Add(15);
            s2.Add(18);
            string expecting = "{15, 18}";
            string result    = (s2.And(s)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #22
0
        public virtual StateCluster BuildRange(int a, int b)
        {
            NFAState   left  = NewState();
            NFAState   right = NewState();
            Label      label = new Label(IntervalSet.Of(a, b));
            Transition e     = new Transition(label, right);

            left.AddTransition(e);
            StateCluster g = new StateCluster(left, right);

            return(g);
        }
Example #23
0
        public void TestNotSet() /*throws Exception*/
        {
            IntervalSet vocabulary = IntervalSet.Of(1, 1000);
            IntervalSet s          = IntervalSet.Of(50, 60);

            s.Add(5);
            s.Add(250, 300);
            string expecting = "{1..4, 6..49, 61..249, 301..1000}";
            string result    = (s.Complement(vocabulary)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #24
0
        public void TestMergeOfRangesAndSingleValues() /*throws Exception*/
        {
            // {0..41, 42, 43..65534}
            IntervalSet s = IntervalSet.Of(0, 41);

            s.Add(42);
            s.Add(43, 65534);
            string expecting = "0..65534";
            string result    = s.ToString();

            assertEquals(result, expecting);
        }
Example #25
0
        public void TestMergeWhereAdditionMergesThreeExistingIntervals()
        {
            IntervalSet s = new IntervalSet();

            s.Add(0);
            s.Add(3);
            s.Add(5);
            s.Add(0, 7);
            String expecting = "0..7";
            String result    = s.ToString();

            Assert.AreEqual(expecting, result);
        }
Example #26
0
        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();

            Assert.AreEqual(result, expecting);
        }
Example #27
0
        public void TestNotRIntersectionNotT() /*throws Exception*/
        {
            IntervalSet s = IntervalSet.Of(0, 's');

            s.Add('u', 200);
            IntervalSet s2 = IntervalSet.Of(0, 'q');

            s2.Add('s', 200);
            string expecting = "{0..113, 115, 117..200}";
            string result    = (s.And(s2)).ToString();

            Assert.AreEqual(result, expecting);
        }
Example #28
0
        public void TestMembership() /*throws Exception*/
        {
            IntervalSet s = IntervalSet.Of(15, 15);

            s.Add(50, 60);
            Assert.IsTrue(!s.Contains(0));
            Assert.IsTrue(!s.Contains(20));
            Assert.IsTrue(!s.Contains(100));
            Assert.IsTrue(s.Contains(15));
            Assert.IsTrue(s.Contains(55));
            Assert.IsTrue(s.Contains(50));
            Assert.IsTrue(s.Contains(60));
        }
Example #29
0
        public void TestToList() /*throws Exception*/
        {
            IntervalSet s = IntervalSet.Of(20, 25);

            s.Add(50, 55);
            s.Add(5, 5);
            string expecting = "[5, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55]";
            IList  foo       = new List <object>();
            //String result = String.valueOf( s.toList() );
            string result = "[" + string.Join(", ", s.ToArray().Select(i => i.ToString()).ToArray()) + "]";

            Assert.AreEqual(result, expecting);
        }
Example #30
0
        public void TestMergeWhereAdditionMergesTwoExistingIntervals() /*throws Exception*/
        {
            // 42, 10, {0..9, 11..41, 43..65534}
            IntervalSet s = IntervalSet.Of(42);

            s.Add(10);
            s.Add(0, 9);
            s.Add(43, 65534);
            s.Add(11, 41);
            string expecting = "0..65534";
            string result    = s.ToString();

            Assert.AreEqual(result, expecting);
        }
Example #31
0
 public void TestIsolatedElements()
 {
     IntervalSet s = new IntervalSet();
     s.Add( 1 );
     s.Add( 'z' );
     s.Add( '\uFFF0' );
     string expecting = "{1, 122, 65520}";
     Assert.AreEqual( s.ToString(), expecting );
 }
Example #32
0
 public void TestMixedRangesAndElements()
 {
     IntervalSet s = new IntervalSet();
     s.Add( 1 );
     s.Add( 'a', 'z' );
     s.Add( '0', '9' );
     string expecting = "{1, 48..57, 97..122}";
     Assert.AreEqual( s.ToString(), expecting );
 }
Example #33
0
 public virtual void Remove( int a )
 {
     tokenTypeSet = (IntervalSet)tokenTypeSet.Subtract( IntervalSet.Of( a ) );
 }
Example #34
0
 public LookaheadSet()
 {
     tokenTypeSet = new IntervalSet();
 }
Example #35
0
 public LookaheadSet( int atom )
 {
     tokenTypeSet = IntervalSet.Of( atom );
 }