public void EpsilonPfsaBuilderTest() { var fsa = SfsaBuilder.FromEpsilon(); Assert.Single(fsa.States); Assert.False(fsa.Recognize("a")); Assert.False(fsa.Recognize("abc")); Assert.True(fsa.Recognize(string.Empty)); }
public void EpsilonFreeSimpleConstructionTest() { // a* var fsa = SfsaBuilder.FromWord("a").Star().EpsilonFree(); Assert.DoesNotContain(fsa.Transitions, t => t.Label == null); Assert.DoesNotContain(new[] { "ca", "aaba", "b", "cc" }, fsa.Recognize); Assert.True(new[] { "aaaa", "a", "aa", string.Empty, "aaaaaaaa" }.All(fsa.Recognize)); }
Sfsa Term() { if (this.HasMoreChars() && this.Peek() != ')' && this.Peek() != '|') { return(this.Factor().Concat(this.Term())); } return(SfsaBuilder.FromEpsilon()); }
public void WordPfsaBuilderTest() { var fsa = SfsaBuilder.FromWord("abc"); Assert.Equal(4, fsa.States.Count); Assert.False(fsa.Recognize(string.Empty)); Assert.False(fsa.Recognize("a")); Assert.False(fsa.Recognize("abca")); Assert.True(fsa.Recognize("abc")); }
public void StarPfsaTest() { var fsa = SfsaBuilder.FromWord("a").Star(); Assert.Equal(3, fsa.States.Count); Assert.Single(fsa.Initial); Assert.Equal(2, fsa.Final.Count); Assert.False(fsa.Recognize("ab")); Assert.True(new[] { "aaaa", "a", "aa", string.Empty, "aaaaaaaa" }.All(fsa.Recognize)); }
public void ComplexPfsaConstructionTest1() { // (a|b)*c var fsa = SfsaBuilder.FromWord("a") .Union(SfsaBuilder.FromWord("b")) .Star() .Concat(SfsaBuilder.FromWord("c")); Assert.DoesNotContain(new[] { "ca", "aaba", string.Empty, "cc" }, fsa.Recognize); Assert.True(new[] { "abbac", "ac", "bc", "ababbbbac", "c" }.All(fsa.Recognize)); }
public void AllPfsaTest() { var fsa = SfsaBuilder.Any().Star(); Assert.Equal(3, fsa.States.Count); Assert.Equal(1, fsa.Initial.Count); Assert.Equal(2, fsa.Final.Count); Assert.True(fsa.Recognize("d")); Assert.True(fsa.Recognize("ad")); Assert.True(new[] { "ab", string.Empty, "abc", "bbbac", "cba", "cbcbbcaaaaacb" }.All(fsa.Recognize)); }
public void OptionPfsaTest() { var fsa = SfsaBuilder.FromWord("ab").Optional(); Assert.Equal(4, fsa.States.Count); Assert.Equal(2, fsa.Initial.Count); Assert.Equal(2, fsa.Final.Count); Assert.False(fsa.Recognize("b")); Assert.False(fsa.Recognize("a")); Assert.True(new[] { "ab", string.Empty }.All(fsa.Recognize)); }
public void FromSymbolSetPfsaTest() { var fsa = SfsaBuilder.FromSymbolSet(new HashSet <char> { 'a', 'b', 'c' }); Assert.Equal(2, fsa.States.Count); Assert.False(fsa.Recognize(string.Empty)); Assert.False(fsa.Recognize("d")); Assert.False(fsa.Recognize("ab")); Assert.True(new[] { "b", "a", "c" }.All(fsa.Recognize)); }
public void EpsilonFreeConstructionTest() { // (a|b)+c var fsa = SfsaBuilder.FromWord("a") .Union(SfsaBuilder.FromWord("b")) .Plus() .Concat(SfsaBuilder.FromWord("c")) .EpsilonFree(); Assert.DoesNotContain(fsa.Transitions, t => t.Label == null); Assert.True(new[] { "abbac", "ac", "bc", "ababbbbac", "aac" }.All(fsa.Recognize)); Assert.DoesNotContain(new[] { "ca", "aaba", string.Empty, "cc", "c" }, fsa.Recognize); }
public void StarPfsaTest1() { var fsa = SfsaBuilder.FromWord("abc").Star(); Assert.Equal(5, fsa.States.Count); Assert.Single(fsa.Initial); Assert.Equal(2, fsa.Final.Count); Assert.False(fsa.Recognize("abcabcabcb")); Assert.False(fsa.Recognize("ab")); Assert.True(fsa.Recognize(string.Empty)); Assert.True(fsa.Recognize("abc")); Assert.True(fsa.Recognize("abcabcabc")); }
public void UnionEpsilonPfsaTest() { var fsa1 = SfsaBuilder.FromWord("abc"); var fsa2 = SfsaBuilder.FromEpsilon(); var fsa = fsa1.Union(fsa2); Assert.Equal(5, fsa.States.Count); Assert.Equal(2, fsa.Initial.Count); Assert.Equal(2, fsa.Final.Count); Assert.True(fsa.Recognize(string.Empty)); Assert.False(fsa.Recognize("a")); Assert.True(fsa.Recognize("abc")); Assert.False(fsa.Recognize("abca")); }
public void ComplexPfsaConstructionTest2() { // .+@.+\.com var allPlus = SfsaBuilder.Any().Plus(); var fsa = allPlus .Concat( SfsaBuilder.FromWord("@"), allPlus, SfsaBuilder.FromWord(".com")) .Determinize(); Assert.DoesNotContain(new[] { "*****@*****.**", "you_gmail.com", "*****@*****.**", "*****@*****.**" }, fsa.Recognize); Assert.True(new[] { "*****@*****.**", "*****@*****.**", "*****@*****.**" }.All(fsa.Recognize)); }
public void ComplexPfsaConstructionTest() { // ab*c var fsa = SfsaBuilder.FromWord("a").Concat( SfsaBuilder.FromWord("b").Star(), SfsaBuilder.FromWord("c")); Assert.False(fsa.Recognize(string.Empty)); Assert.False(fsa.Recognize("ab")); Assert.True(fsa.Recognize("abc")); Assert.True(fsa.Recognize("ac")); Assert.True(fsa.Recognize("abbbbc")); }
public void ConcatPfsaTest() { var fsa1 = SfsaBuilder.FromWord("abc"); var fsa2 = SfsaBuilder.FromWord("de"); var fsa = fsa1.Concat(fsa2); Assert.Equal(7, fsa.States.Count); Assert.Single(fsa.Initial); Assert.Single(fsa.Final); Assert.False(fsa.Recognize(string.Empty)); Assert.False(fsa.Recognize("a")); Assert.False(fsa.Recognize("abc")); Assert.False(fsa.Recognize("de")); Assert.True(fsa.Recognize("abcde")); }