Exemplo n.º 1
0
        public void TrySubtractLookahead()
        {
            var set1 = ParseItemSet.New(new ParseItem[] { _item10, _item11, _item20 });

            var laA = SegmentSet.New(new Segment[] { _lookaheadA });
            var laB = SegmentSet.New(new Segment[] { _lookaheadB });
            var laC = SegmentSet.New(new Segment[] { _lookaheadC });

            var laAB  = SegmentSet.New(new Segment[] { _lookaheadA, _lookaheadB });
            var laBC  = SegmentSet.New(new Segment[] { _lookaheadB, _lookaheadC });
            var laABC = SegmentSet.New(new Segment[] { _lookaheadA, _lookaheadB, _lookaheadC });

            set1.SetLookahead(_item10, laAB);
            set1.SetLookahead(_item11, laBC);
            set1.SetLookahead(_item20, laABC);

            Assert.That(set1.GetLookahead(_item10), Is.EqualTo(laAB));
            Assert.That(set1.GetLookahead(_item11), Is.EqualTo(laBC));
            Assert.That(set1.GetLookahead(_item20), Is.EqualTo(laABC));

            set1.SubtractLookaheads(laB);

            Assert.That(set1.GetLookahead(_item10), Is.EqualTo(laA));
            Assert.That(set1.GetLookahead(_item11), Is.EqualTo(laC));
            Assert.That(set1.GetLookahead(_item20), Is.EqualTo(laA.Union(laC)));
        }
Exemplo n.º 2
0
        public void TryUnionLookahead()
        {
            var set1 = ParseItemSet.New(new ParseItem[] { _item10, _item11, _item20 });

            var la1 = SegmentSet.New(new Segment[] { _lookaheadA, _lookaheadB });
            var la2 = SegmentSet.New(new Segment[] { _lookaheadB, _lookaheadC });
            var la3 = SegmentSet.New(new Segment[] { _lookaheadA, _lookaheadB, _lookaheadC });

            Assert.That(set1.GetLookahead(_item10), Is.EqualTo(SegmentSet.EmptySet));
            Assert.That(set1.GetLookahead(_item11), Is.EqualTo(SegmentSet.EmptySet));
            Assert.That(set1.GetLookahead(_item20), Is.EqualTo(SegmentSet.EmptySet));

            Assert.That(set1.TryUnionLookahead(_item10, la1), Is.EqualTo(true));
            Assert.That(set1.TryUnionLookahead(_item11, la1), Is.EqualTo(true));

            Assert.That(set1.GetLookahead(_item10), Is.EqualTo(la1));
            Assert.That(set1.GetLookahead(_item11), Is.EqualTo(la1));
            Assert.That(set1.GetLookahead(_item20), Is.EqualTo(SegmentSet.EmptySet));

            Assert.That(set1.TryUnionLookahead(_item10, la2), Is.EqualTo(true));

            Assert.That(set1.GetLookahead(_item10), Is.EqualTo(la3));
            Assert.That(set1.GetLookahead(_item11), Is.EqualTo(la1));
            Assert.That(set1.GetLookahead(_item20), Is.EqualTo(SegmentSet.EmptySet));

            Assert.That(set1.TryUnionLookahead(_item10, la1), Is.EqualTo(false));

            Assert.That(set1.GetLookahead(_item10), Is.EqualTo(la3));
            Assert.That(set1.GetLookahead(_item11), Is.EqualTo(la1));
            Assert.That(set1.GetLookahead(_item20), Is.EqualTo(SegmentSet.EmptySet));
        }
Exemplo n.º 3
0
        public void Contains()
        {
            var set = ParseItemSet.New(new ParseItem[] { _item10, _item10, _item11, _item11, _item20 });

            Assert.That(set.Contains(_item10), Is.EqualTo(true));
            Assert.That(set.Contains(_item11), Is.EqualTo(true));
            Assert.That(set.Contains(_item20), Is.EqualTo(true));
            Assert.That(set.Contains(_item21), Is.EqualTo(false));
        }
Exemplo n.º 4
0
        public void GetTransitionKernels()
        {
            var set1 = ParseItemSet.New(new ParseItem[] { _item10, _item11, _item20, _item21 });

            var transitions = set1.GetTransitionKernels();

            Assert.That(transitions.Count, Is.EqualTo(2));
            Assert.That(transitions[_segment1], Is.EquivalentTo(new ParseItem[] { _item11 }));
            Assert.That(transitions[_segment2], Is.EquivalentTo(new ParseItem[] { _item21 }));
        }
Exemplo n.º 5
0
        public void New()
        {
            var set1 = ParseItemSet.New(new ParseItem[] { _item10, _item10, _item11, _item20 });
            var set2 = ParseItemSet.New(new ParseItem[] { _item10, _item11, _item20 });
            var set3 = ParseItemSet.New(new ParseItem[] { _item10 });

            Assert.That(set1.Equals(set1), Is.EqualTo(true));
            Assert.That(set1.Equals(set2), Is.EqualTo(true));
            Assert.That(set1.Equals(set3), Is.EqualTo(false));

            Assert.That(set2.Equals(set1), Is.EqualTo(true));
            Assert.That(set2.Equals(set2), Is.EqualTo(true));
            Assert.That(set2.Equals(set3), Is.EqualTo(false));

            Assert.That(set3.Equals(set1), Is.EqualTo(false));
            Assert.That(set3.Equals(set2), Is.EqualTo(false));
            Assert.That(set3.Equals(set3), Is.EqualTo(true));
        }
Exemplo n.º 6
0
        public void Equality()
        {
            var set1 = ParseItemSet.New(new ParseItem[]
            {
                _item10,
                _item10,
                _item10,
            });

            var set2 = ParseItemSet.New(new ParseItem[]
            {
                _item10,
            });

            var set3 = ParseItemSet.New(new ParseItem[]
            {
                _item10,
                _item11,
            });

            Assert.That(set1.Equals(set1), Is.EqualTo(true));
            Assert.That(set1.Equals(set2), Is.EqualTo(true));
            Assert.That(set1.Equals(set3), Is.EqualTo(false));

            Assert.That(set2.Equals(set1), Is.EqualTo(true));
            Assert.That(set2.Equals(set2), Is.EqualTo(true));
            Assert.That(set2.Equals(set3), Is.EqualTo(false));

            Assert.That(set3.Equals(set1), Is.EqualTo(false));
            Assert.That(set3.Equals(set2), Is.EqualTo(false));
            Assert.That(set3.Equals(set3), Is.EqualTo(true));

            Assert.That(set1.GetHashCode(), Is.EqualTo(set1.GetHashCode()));
            Assert.That(set1.GetHashCode(), Is.EqualTo(set2.GetHashCode()));
            Assert.That(set1.GetHashCode(), Is.Not.EqualTo(set3.GetHashCode()));

            Assert.That(set2.GetHashCode(), Is.EqualTo(set1.GetHashCode()));
            Assert.That(set2.GetHashCode(), Is.EqualTo(set2.GetHashCode()));
            Assert.That(set2.GetHashCode(), Is.Not.EqualTo(set3.GetHashCode()));

            Assert.That(set3.GetHashCode(), Is.Not.EqualTo(set1.GetHashCode()));
            Assert.That(set3.GetHashCode(), Is.Not.EqualTo(set2.GetHashCode()));
            Assert.That(set3.GetHashCode(), Is.EqualTo(set3.GetHashCode()));
        }