-
Notifications
You must be signed in to change notification settings - Fork 0
/
automaton.test.ts
70 lines (60 loc) · 2.41 KB
/
automaton.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as modelMap from './models.ts';
import DFA, {
EPSILON, IDFAInput,
} from './automaton.ts';
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
Deno.test("Should load a simple DF", () => {
const graph = new DFA(modelMap.simple);
assertEquals(graph.getStructure(), modelMap.simple);
});
Deno.test("Should execute a simple DFA with accepted input", () => {
const graph = new DFA(modelMap.simple);
const { path, accepted} = graph.process('010');
assertEquals(accepted, true);
assertEquals(path, ['C', 'A', 'C']);
});
Deno.test("Should execute a simple DFA with rejected input", () => {
const graph = new DFA(modelMap.simple);
const { path, accepted } = graph.process("0101");
assertEquals(accepted, false);
assertEquals(path, ['C', 'A', 'C', 'A']);
});
Deno.test(`Should load an ${EPSILON} NFA`, () => {
const graph = new DFA(modelMap.epsilon);
assertEquals(graph.getStructure(), modelMap.epsilon);
});
Deno.test(`Should execute an ${EPSILON} NFA with accepted input`, () => {
const graph = new DFA(modelMap.epsilon);
const { path, accepted } = graph.process("010");
assertEquals(accepted, true);
assertEquals(path, ["zyx", "zy", "z"]);
});
Deno.test(`Should execute an ${EPSILON} NFA with rejected input`, () => {
const graph = new DFA(modelMap.epsilon);
const { path, accepted } = graph.process("0102");
assertEquals(accepted, false);
assertEquals(path, ["zyx", "zy", "z", undefined]);
});
Deno.test(`Should load an ${EPSILON}-free NFA`, () => {
const graph = new DFA(modelMap.epsilonFree);
assertEquals(graph.getStructure(), modelMap.epsilonFree);
});
Deno.test(`Should execute an ${EPSILON}-free NFA with accepted input`, () => {
const graph = new DFA(modelMap.epsilonFree);
const { path, accepted } = graph.process("010");
assertEquals(accepted, true);
assertEquals(path, ["edcba", "edb", "ec"]);
});
Deno.test(`Should execute an ${EPSILON}-free NFA with rejected input`, () => {
const graph = new DFA(modelMap.epsilonFree);
const { path, accepted } = graph.process("0102");
assertEquals(accepted, false);
assertEquals(path, ["edcba", "edb", "ec", undefined]);
});
Deno.test(`Should successfully load all ${Object.keys(modelMap).length} test cases`, () => {
Object.keys(modelMap).forEach((model: string) => {
const structure = (modelMap as { [s: string]: IDFAInput })[model] as IDFAInput;
const graph = new DFA(structure);
assertEquals(graph.getStructure(), structure);
});
});