public void RegexToNFA_ConvertsValidRegexCorrectly(string regex, char[] alphabet, string[] validWords, string[] invalidWords, int expectedStates)
        {
            var automaton = AutomatonUtil.RegexToAutomaton(regex, alphabet);

            Assert.Equal(expectedStates, automaton.States.Count);
            foreach (var validWord in validWords)
            {
                Assert.True(automaton.IsValidWord(validWord));
            }
            foreach (var invalidWord in invalidWords)
            {
                Assert.False(automaton.IsValidWord(invalidWord));
            }
        }
Beispiel #2
0
        internal static Automaton RegularLanguageRegexToCanonicalWordAcceptingDfa(string regex, string regexName = "")
        {
            // It isn't required to convert to DFA, but as it is an inexpensive operation for the automaton created via the thompson construction,
            // it probably will end up saving time overall by reducing the time on the other steps.

            var sw        = Stopwatch.StartNew();
            var automaton = TimedFunction(() => AutomatonUtil.RegexToAutomaton(regex, Constants.RegularLanguage.Symbols),
                                          $"Regex to Thompson NFA for regex {regexName}");

            automaton = TimedFunction(() => automaton.ToDFA(),
                                      $"Thompson NFA to DFA for regex {regexName}");
            TimedFunction(() => automaton.UpdateAutomatonToAcceptCanonicalWords(),
                          $"Canonicalisation of DFA for regex {regexName}");
            automaton = TimedFunction(() => automaton.ToDFA(),
                                      $"Canonicalised NFA to DFA for regex {regexName}");
            return(automaton);
        }
 public void RegexToPostFix_ConvertsCorrectly(string infixRegex, string expectedPostfix)
 {
     Assert.Equal(expectedPostfix, String.Join("", AutomatonUtil.RegexToPostfix(infixRegex)));
 }