Add more examples
This commit is contained in:
parent
0f5d632388
commit
fa48bc49d1
4 changed files with 89 additions and 40 deletions
41
ContainsSequence.fs
Normal file
41
ContainsSequence.fs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
namespace Tests
|
||||
|
||||
open System
|
||||
open NFA
|
||||
open DFA
|
||||
|
||||
module ContainsSequence =
|
||||
|
||||
let contains0101:NFA = {
|
||||
sigma = Seq.toList "01";
|
||||
states = [
|
||||
{name = "q0"};
|
||||
{name = "q1"};
|
||||
{name = "q2"};
|
||||
{name = "q3"}
|
||||
{name = "yes"}
|
||||
];
|
||||
delta = (fun x y ->
|
||||
match (x, y) with
|
||||
| ({name = "q0"}, '0') -> [{name = "q0"}; {name = "q1"}]
|
||||
| ({name = "q1"}, '1') -> [{name = "q0"}; {name = "q2"}]
|
||||
| ({name = "q2"}, '0') -> [{name = "q0"}; {name = "q3"}]
|
||||
| ({name = "q3"}, '1') -> [{name = "yes"}]
|
||||
| ({name = "yes"}, _) -> [{name = "yes"}]
|
||||
| _ -> []
|
||||
);
|
||||
beginState = {name = "q0"};
|
||||
acceptingStates = [{name = "yes"}]
|
||||
|
||||
}
|
||||
|
||||
let test =
|
||||
printfn "Testing contains sequence NFA"
|
||||
printfn "Contains '0101' ?"
|
||||
printfn "0101: %b" (NFA.acceptsWord contains0101 "0101")
|
||||
printfn "0000: %b" (NFA.acceptsWord contains0101 "0000")
|
||||
printfn "1010: %b" (NFA.acceptsWord contains0101 "1010")
|
||||
printfn "0100: %b" (NFA.acceptsWord contains0101 "0100")
|
||||
printfn "00101: %b" (NFA.acceptsWord contains0101 "00101")
|
||||
printfn "01011: %b" (NFA.acceptsWord contains0101 "01011")
|
||||
0
|
||||
Loading…
Add table
Add a link
Reference in a new issue