public void TestSingleElement()
        {
            IntervalSet s         = IntervalSet.Of(99);
            String      expecting = "99";

            Assert.AreEqual(s.ToString(), expecting);
        }
        public void TestComplement2()
        {
            IntervalSet s         = IntervalSet.Of(100, 101);
            IntervalSet s2        = IntervalSet.Of(100, 102);
            String      expecting = "102";
            String      result    = (s.Complement(s2)).ToString();

            Assert.AreEqual(expecting, result);
        }
        public void TestEmptyIntersection()
        {
            IntervalSet s         = IntervalSet.Of('a', 'z');
            IntervalSet s2        = IntervalSet.Of('0', '9');
            String      expecting = "{}";
            String      result    = (s.And(s2)).ToString();

            Assert.AreEqual(expecting, result);
        }
        public void TestNotSetEdgeElement()
        {
            IntervalSet vocabulary = IntervalSet.Of(1, 2);
            IntervalSet s          = IntervalSet.Of(1);
            String      expecting  = "2";
            String      result     = (s.Complement(vocabulary)).ToString();

            Assert.AreEqual(expecting, result);
        }
        public void TestSubtractOfCompletelyCoveredRange()
        {
            IntervalSet s         = IntervalSet.Of(10, 20);
            IntervalSet s2        = IntervalSet.Of(1, 25);
            String      expecting = "{}";
            String      result    = (s.Subtract(s2)).ToString();

            Assert.AreEqual(expecting, result);
        }
        public void TestSimpleAnd()
        {
            IntervalSet s         = IntervalSet.Of(10, 20);
            IntervalSet s2        = IntervalSet.Of(13, 15);
            String      expecting = "{13..15}";
            String      result    = (s.And(s2)).ToString();

            Assert.AreEqual(expecting, result);
        }
        public void TestSubtractOfCompletelyContainedRange()
        {
            IntervalSet s         = IntervalSet.Of(10, 20);
            IntervalSet s2        = IntervalSet.Of(12, 15);
            String      expecting = "{10..11, 16..20}";
            String      result    = (s.Subtract(s2)).ToString();

            Assert.AreEqual(expecting, result);
        }
        public void TestRangeAndIsolatedElement()
        {
            IntervalSet s         = IntervalSet.Of('a', 'z');
            IntervalSet s2        = IntervalSet.Of('d');
            String      expecting = "100";
            String      result    = (s.And(s2)).ToString();

            Assert.AreEqual(expecting, result);
        }
        public void TestEmptyIntersectionSingleElements()
        {
            IntervalSet s         = IntervalSet.Of('a');
            IntervalSet s2        = IntervalSet.Of('d');
            String      expecting = "{}";
            String      result    = (s.And(s2)).ToString();

            Assert.AreEqual(expecting, result);
        }
Example #10
0
 public SetTransition(ATNState target, IntervalSet set) : base(target)
 {
     // TODO (sam): should we really allow null here?
     if (set == null)
     {
         set = IntervalSet.Of(TokenConstants.InvalidType);
     }
     this.set = set;
 }
Example #11
0
        public void TestComplement3()
        {
            IntervalSet s = IntervalSet.Of(1, 96);

            s.Add(99, Lexer.MaxCharValue);
            String expecting = "{97..98}";
            String result    = (s.Complement(1, Lexer.MaxCharValue)).ToString();

            Assert.AreEqual(expecting, result);
        }
Example #12
0
        public void TestMergeWithDoubleOverlap()
        {
            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(expecting, result);
        }
Example #13
0
        public void TestSimpleEquals()
        {
            IntervalSet s  = IntervalSet.Of(10, 20);
            IntervalSet s2 = IntervalSet.Of(10, 20);

            Assert.AreEqual(s, s2);

            IntervalSet s3 = IntervalSet.Of(15, 55);

            Assert.AreNotEqual(s, s3);
        }
Example #14
0
        public void TestSingleElementMinusDisjointSet()
        {
            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(expecting, result);
        }
Example #15
0
        public void TestMergeOfRangesAndSingleValuesReverse()
        {
            IntervalSet s = IntervalSet.Of(43, 65534);

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

            Assert.AreEqual(expecting, result);
        }
Example #16
0
        public void TestRmSingleElement()
        {
            IntervalSet s = IntervalSet.Of(1, 10);

            s.Add(-3, -3);
            s.Remove(-3);
            String expecting = "{1..10}";
            String result    = s.ToString();

            Assert.AreEqual(expecting, result);
        }
Example #17
0
        public void TestNotSingleElement()
        {
            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(expecting, result);
        }
Example #18
0
        public void TestRmRightSide()
        {
            IntervalSet s = IntervalSet.Of(1, 10);

            s.Add(-3, -3);
            s.Remove(10);
            String expecting = "{-3, 1..9}";
            String result    = s.ToString();

            Assert.AreEqual(expecting, result);
        }
Example #19
0
        public void TestRmMiddleRange()
        {
            IntervalSet s = IntervalSet.Of(1, 10);

            s.Add(-3, -3);
            s.Remove(5);
            String expecting = "{-3, 1..4, 6..10}";
            String result    = s.ToString();

            Assert.AreEqual(expecting, result);
        }
Example #20
0
        public void TestToList()
        {
            IntervalSet s = IntervalSet.Of(20, 25);

            s.Add(50, 55);
            s.Add(5, 5);
            int[]       expecting = { 5, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55 };
            IList <int> result    = s.ToList();

            CollectionAssert.AreEquivalent(expecting, result.ToArray());
        }
Example #21
0
        public void TestSize()
        {
            IntervalSet s = IntervalSet.Of(20, 30);

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

            Assert.AreEqual(expecting, result);
        }
Example #22
0
        public void TestIntersectionWithTwoContainedElementsReversed()
        {
            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(expecting, result);
        }
Example #23
0
        public void TestNotSet()
        {
            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(expecting, result);
        }
Example #24
0
        public void TestSubtractOfWackyRange()
        {
            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(expecting, result);
        }
Example #25
0
        public void TestMembership()
        {
            IntervalSet s = IntervalSet.Of(15, 15);

            s.Add(50, 60);
            Assert.IsFalse(s.Contains(0));
            Assert.IsFalse(s.Contains(20));
            Assert.IsFalse(s.Contains(100));
            Assert.IsTrue(s.Contains(15));
            Assert.IsTrue(s.Contains(55));
            Assert.IsTrue(s.Contains(50));
            Assert.IsTrue(s.Contains(60));
        }
Example #26
0
        public void TestNotRIntersectionNotT()
        {
            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(expecting, result);
        }
Example #27
0
        public void TestMergeWhereAdditionMergesTwoExistingIntervals()
        {
            // 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(expecting, result);
        }
Example #28
0
        public void TestSubtractOfOverlappingRangeFromLeft()
        {
            IntervalSet s         = IntervalSet.Of(10, 20);
            IntervalSet s2        = IntervalSet.Of(5, 11);
            String      expecting = "{12..20}";
            String      result    = (s.Subtract(s2)).ToString();

            Assert.AreEqual(expecting, result);

            IntervalSet s3 = IntervalSet.Of(5, 10);

            expecting = "{11..20}";
            result    = (s.Subtract(s3)).ToString();
            Assert.AreEqual(expecting, result);
        }
Example #29
0
        public void TestSubtractOfOverlappingRangeFromRight()
        {
            IntervalSet s         = IntervalSet.Of(10, 20);
            IntervalSet s2        = IntervalSet.Of(15, 25);
            String      expecting = "{10..14}";
            String      result    = (s.Subtract(s2)).ToString();

            Assert.AreEqual(expecting, result);

            IntervalSet s3 = IntervalSet.Of(20, 25);

            expecting = "{10..19}";
            result    = (s.Subtract(s3)).ToString();
            Assert.AreEqual(expecting, result);
        }
Example #30
0
        public void TestNotSetFragmentedVocabulary()
        {
            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();

            Assert.AreEqual(expecting, result);
        }