Add more examples

This commit is contained in:
joachimschmidt557 2019-02-20 19:18:48 +01:00
parent 0f5d632388
commit fa48bc49d1
4 changed files with 89 additions and 40 deletions

View file

@ -1,46 +1,50 @@
module Tests
namespace 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"}]
}
module IsNumeric =
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 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")
printfn "Testing numeric checker NFA"
printfn "0101: %A" (NFA.acceptsWord numericNFA "0101")
printfn "01a1: %b" (NFA.acceptsWord numericNFA "01a1")
0
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 "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