示例#1
0
        public void NfaReduceTest()
        {
            var graph = new Graph("h");

            graph.MarkEnd("kw_h", "h");

            var g2 = graph.Create("y");
            var g3 = graph.Create("m");

            g2.Union(g3);
            g2.MarkEnd("kw_you", "you");

            graph = graph.Union(g2);

            graph.Reduce();

            var expected = NfaArray.Create()
                           .Epsilon2(index: 8, left: 6, right: 1)
                           .Match(index: 1, left: 0, match: 1)
                           .Epsilon2(index: 6, left: 5, right: 3)
                           .Epsilon1(index: 0, state: 1, right: 9)
                           .Match(index: 3, left: 7, match: 2)
                           .Match(index: 5, left: 7, match: 3)
                           .None(index: 9)
                           .Epsilon1(index: 7, state: 2, right: 9)
                           .ToArray();

            var actual = graph.ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }
示例#2
0
        public void ConcatTest()
        {
            var graph = new Graph("c");
            var h     = graph.Create("h");

            graph.Concatenate(h);

            var actual = graph.ToArray();


            var expected = NfaArray.Create()
                           .Match(index: 1, left: 0, match: 1)
                           .Epsilon1(index: 0, right: 3)
                           .Match(index: 3, left: 2, match: 2)
                           .None(index: 2)
                           .ToArray();

            CollectionAssert.AreEqual(expected, actual);
        }