Exemplo n.º 1
0
        public void Misc()
        {
            NFA nfa = NFA.Sequence(NFA.Star(NFA.Or(NFA.Char('a'), NFA.Char('b'))), NFA.Char('a'), NFA.Char('b'), NFA.Char('b')); // (a|b)*abb
            DFA dfa = nfa.ToDfa();

            Assert.IsFalse(dfa.IsMatch(""));
            Assert.IsFalse(dfa.IsMatch("a"));
            Assert.IsFalse(dfa.IsMatch("b"));
            Assert.IsFalse(dfa.IsMatch("ab"));

            Assert.IsTrue(dfa.IsMatch("abb"));
            Assert.IsTrue(dfa.IsMatch("aabb"));
            Assert.IsTrue(dfa.IsMatch("babb"));
            Assert.IsTrue(dfa.IsMatch("ababb"));
            Assert.IsTrue(dfa.IsMatch("aaabb"));
            Assert.IsTrue(dfa.IsMatch("bbabb"));
            Assert.IsTrue(dfa.IsMatch("abababb"));
        }
Exemplo n.º 2
0
        public void Star()
        {
            NFA nfa = NFA.Star(NFA.Sequence(NFA.Char('a'), NFA.Char('b')));
            DFA dfa = nfa.ToDfa();

            Assert.IsTrue(dfa.IsMatch(""));

            Assert.IsFalse(dfa.IsMatch("a"));
            Assert.IsFalse(dfa.IsMatch("b"));
            Assert.IsFalse(dfa.IsMatch("aa"));
            Assert.IsFalse(dfa.IsMatch("bb"));
            Assert.IsFalse(dfa.IsMatch("ba"));
            Assert.IsFalse(dfa.IsMatch("cc"));
            Assert.IsFalse(dfa.IsMatch("aaa"));
            Assert.IsFalse(dfa.IsMatch("aba"));
            Assert.IsFalse(dfa.IsMatch("abb"));

            Assert.IsTrue(dfa.IsMatch("ab"));
            Assert.IsTrue(dfa.IsMatch("abab"));
            Assert.IsTrue(dfa.IsMatch("ababab"));
        }