Fauton
A library to test any finite automaton(FA) with arbitrary alphabets.
Features
- Test any dfa/nfa/ε-nfa
- Supports arbitrary alphabets
- Easy to use api to generate input strings
- ε-nfa to nfa conversion
- Generate artifacts files for each automaton
- Highly customizable
- Full typescript support
- Simple concise error messages for invalid finite automaton
- Generate full graph for ε-nfa given a string
Example (A simple dfa)
Lets start out with a simple dfa, that checks whether an input string starts with bc
. The alphabets of the dfa are a, b, c
const { DeterministicFiniteAutomaton, FiniteAutomataTest } = require('fauton');
const path = require('path');
const startsWithBC = new DeterministicFiniteAutomaton(
(inputString) => inputString.startsWith('bc'),
{
alphabets: ['a', 'b', 'c'],
description: 'Starts with bc',
final_states: ['Q3'],
label: 'starts_with_bc',
start_state: 'Q0',
states: ['Q0', 'Q1', 'Q2', 'Q3'],
transitions: {
Q0: ['Q2', 'Q1', 'Q2'],
Q1: ['Q2', 'Q2', 'Q3'],
Q2: 'loop',
Q3: 'loop',
},
}
);
Internally this is how the transitions map will be generated
const transitions = {
Q0: {
a: 'Q2',
b: 'Q1',
c: 'Q2',
},
Q1: {
a: 'Q2',
b: 'Q2',
c: 'Q3',
},
Q2: {
a: 'Q2',
b: 'Q2',
c: 'Q2',
},
Q3: {
a: 'Q3',
b: 'Q3',
c: 'Q3',
},
};
This is our file directory structure at the moment.
Lets test the dfa we created above and see whether its actually correct or not.
const finiteAutomataTest = new FiniteAutomataTest(path.join(__dirname, 'logs'));
finiteAutomataTest.test([
{
automaton: startsWithBC,
options: {
type: 'generate',
range: {
maxLength: 10,
},
},
},
]);
This is the file structure after running the script. It generates several artifact files for you to investigate.
<dfa.label>.accepted.txt
: Will contain all the strings that will be accepted by the automaton<dfa.label>.aggregate.txt
: Will contain an aggregated result of the test. Its similar to what is shown in the terminal<dfa.label>.case.txt
: Contains the result for each input string test case.<dfa.label>.correct.txt
: Contains all the strings that generated the same boolean result from the logic test callback and the automaton.<dfa.label>.incorrect.txt
: Contains all the strings that generated different boolean result from the logic test callback and the automaton<dfa.label>.input.txt
: Contains all the input strings. Useful when you are feeding random or ranged strings and want to reuse it for later<dfa.label>.rejected.txt
: Contains all the strings that have been rejected bu the automaton
And this is what will be shown in the terminal
Better and more detailed api documentation coming soon very soon !!!
Take a look at the examples folder to understand how to write a dfa test and use this package.