Add a numeric checker
F# |> I❤️
This commit is contained in:
parent
7652c5b86d
commit
20201692a1
9 changed files with 32 additions and 3 deletions
27
IsNumericChecker.fs
Normal file
27
IsNumericChecker.fs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
module Tests
|
||||||
|
|
||||||
|
open System
|
||||||
|
open DFA
|
||||||
|
|
||||||
|
let numericDFA:DFA = {
|
||||||
|
sigma = Seq.toList "01ab";
|
||||||
|
states = [
|
||||||
|
{name = "yes"};
|
||||||
|
{name = "no"}
|
||||||
|
];
|
||||||
|
delta = (fun x y ->
|
||||||
|
match (x, y) with
|
||||||
|
| ({name = "yes"}, '0') -> {name = "yes"}
|
||||||
|
| ({name = "yes"}, '1') -> {name = "yes"}
|
||||||
|
| _ -> {name = "no"}
|
||||||
|
);
|
||||||
|
beginState = {name = "yes"};
|
||||||
|
acceptingStates = [{name = "yes"}]
|
||||||
|
}
|
||||||
|
|
||||||
|
let test =
|
||||||
|
printfn "Testing numeric checker DFA"
|
||||||
|
printfn "Is valid DFA: %b" (DFA.validateDFA numericDFA)
|
||||||
|
printfn "0101: %b" (DFA.acceptsWord numericDFA "0101")
|
||||||
|
printfn "01a1: %b" (DFA.acceptsWord numericDFA "01a1")
|
||||||
|
0
|
||||||
|
|
@ -4,5 +4,6 @@ open System
|
||||||
|
|
||||||
[<EntryPoint>]
|
[<EntryPoint>]
|
||||||
let main argv =
|
let main argv =
|
||||||
printfn "Hello World from F#!"
|
printfn "Finite Automata in F#"
|
||||||
|
Tests.test |> ignore
|
||||||
0 // return an integer exit code
|
0 // return an integer exit code
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -7,6 +7,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DFA.fs" />
|
<Compile Include="DFA.fs" />
|
||||||
<Compile Include="NFA.fs" />
|
<Compile Include="NFA.fs" />
|
||||||
|
<Compile Include="IsNumericChecker.fs" />
|
||||||
<Compile Include="Program.fs" />
|
<Compile Include="Program.fs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue