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
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
module Tests
|
||||
namespace Tests
|
||||
|
||||
open System
|
||||
open DFA
|
||||
open NFA
|
||||
|
||||
module IsNumeric =
|
||||
|
||||
let numericDFA:DFA = {
|
||||
sigma = Seq.toList "01ab";
|
||||
states = [
|
||||
|
|
@ -40,7 +42,9 @@ let test =
|
|||
printfn "Is valid DFA: %b" (DFA.validateDFA numericDFA)
|
||||
printfn "0101: %b" (DFA.acceptsWord numericDFA "0101")
|
||||
printfn "01a1: %b" (DFA.acceptsWord numericDFA "01a1")
|
||||
printfn "Empty: %b" (DFA.acceptsWord numericDFA "")
|
||||
printfn "Testing numeric checker NFA"
|
||||
printfn "0101: %A" (NFA.acceptsWord numericNFA "0101")
|
||||
printfn "01a1: %b" (NFA.acceptsWord numericNFA "01a1")
|
||||
printfn "Empty: %b" (NFA.acceptsWord numericNFA "")
|
||||
0
|
||||
|
|
@ -4,5 +4,8 @@ open System
|
|||
[<EntryPoint>]
|
||||
let main argv =
|
||||
printfn "Finite Automata in F#"
|
||||
Tests.test |> ignore
|
||||
|
||||
Tests.IsNumeric.test |> ignore
|
||||
Tests.ContainsSequence.test |> ignore
|
||||
|
||||
0 // return an integer exit code
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
<Compile Include="DFA.fs" />
|
||||
<Compile Include="NFA.fs" />
|
||||
<Compile Include="IsNumericChecker.fs" />
|
||||
<Compile Include="ContainsSequence.fs" />
|
||||
<Compile Include="Program.fs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Add table
Add a link
Reference in a new issue