fsharp-finite-automata/IsNumericChecker.fs
2019-02-20 18:49:45 +01:00

46 lines
No EOL
1.2 KiB
FSharp

module Tests
open System
open DFA
open NFA
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 numericNFA:NFA = {
sigma = Seq.toList "01ab";
states = [
{name = "yes"}
];
delta = (fun x y ->
match (x, y) with
| ({name = "yes"}, '0') -> [{name = "yes"}]
| ({name = "yes"}, '1') -> [{name = "yes"}]
| _ -> []
);
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")
printfn "Testing numeric checker NFA"
printfn "0101: %A" (NFA.acceptsWord numericNFA "0101")
printfn "01a1: %b" (NFA.acceptsWord numericNFA "01a1")
0