public void Or() { NFA nfa = NFA.Or(NFA.Char('a'), NFA.Char('b')); DFA dfa = nfa.ToDfa(); Assert.IsFalse(dfa.IsMatch("")); Assert.IsTrue(dfa.IsMatch("a")); Assert.IsTrue(dfa.IsMatch("b")); Assert.IsFalse(dfa.IsMatch("aa")); Assert.IsFalse(dfa.IsMatch("ab")); Assert.IsFalse(dfa.IsMatch("bb")); Assert.IsFalse(dfa.IsMatch("ba")); Assert.IsFalse(dfa.IsMatch("aaa")); Assert.IsFalse(dfa.IsMatch("aba")); Assert.IsFalse(dfa.IsMatch("abb")); }
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")); }
public void DateTime() { CharRange digit = new CharRange('0', '9'); CharRange dash = new CharRange('-'); CharRange colon = new CharRange(':'); CharRange seperator = new CharRange(' '); // NFA date = NFA.Sequence(NFA.Repeat(NFA.Char(digit), 4), NFA.Char(dash), NFA.Repeat(NFA.Char(digit), 2), NFA.Char(dash), NFA.Repeat(NFA.Char(digit), 2)); // NFA time = NFA.Sequence(NFA.Repeat(NFA.Char(digit), 2), NFA.Char(colon), NFA.Repeat(NFA.Char(digit), 2)); NFA date = NFA.Sequence( NFA.Char(digit), NFA.Char(digit), NFA.Char(digit), NFA.Char(digit), NFA.Char(dash), NFA.Char(digit), NFA.Char(digit), NFA.Char(dash), NFA.Char(digit), NFA.Char(digit) ); NFA time = NFA.Sequence( NFA.Char(digit), NFA.Char(digit), NFA.Char(colon), NFA.Char(digit), NFA.Char(digit) ); NFA datetime = NFA.Sequence(date, NFA.Char(seperator), time); NFA nfa = NFA.Or(date, time, datetime); DFA dfa = nfa.ToDfa(); Assert.IsTrue(dfa.IsMatch("00:00")); Assert.IsTrue(dfa.IsMatch("23:15")); Assert.IsTrue(dfa.IsMatch("23:59")); Assert.IsTrue(dfa.IsMatch("2014-01-03")); Assert.IsTrue(dfa.IsMatch("0000-00-00")); Assert.IsTrue(dfa.IsMatch("2014-01-03 23:15")); }
public void Time() { CharRange d09 = new CharRange('0', '9'); CharRange d05 = new CharRange('0', '5'); CharRange d03 = new CharRange('0', '3'); CharRange colon = new CharRange(':'); NFA a = NFA.Sequence(NFA.Or(NFA.Char('0'), NFA.Char('1')), NFA.Char(d09), NFA.Char(colon), NFA.Char(d05), NFA.Char(d09)); // [01][0-9]:[0-5][0-9] NFA b = NFA.Sequence(NFA.Char('2'), NFA.Char(d03), NFA.Char(colon), NFA.Char(d05), NFA.Char(d09)); // [2][0-3]:[0-5][0-9] NFA c = NFA.Sequence(NFA.Char('2'), NFA.Char('4'), NFA.Char(colon), NFA.Char('0'), NFA.Char('0')); // [2][4]:[0][0] NFA nfa = NFA.Or(a, b, c); DFA dfa = nfa.ToDfa(); Assert.IsTrue(dfa.IsMatch("00:00")); Assert.IsTrue(dfa.IsMatch("01:50")); Assert.IsTrue(dfa.IsMatch("23:15")); Assert.IsTrue(dfa.IsMatch("23:59")); Assert.IsTrue(dfa.IsMatch("24:00")); Assert.IsFalse(dfa.IsMatch("14:78")); Assert.IsFalse(dfa.IsMatch("24:59")); }