New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dfa-test

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dfa-test - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

dist/libs/DfaModule.d.ts

4

dist/libs/DfaTest.d.ts

@@ -1,2 +0,2 @@

import { IDfaModule } from '../types';
import { DfaModule } from './DfaModule';
declare type IConfigs = {

@@ -29,5 +29,5 @@ type: 'generate';

#private;
constructor(dfas: IDfaModule[], logsPath: string, outputFiles: Partial<IOutputFiles>);
constructor(dfas: DfaModule[], logsPath: string, outputFiles: Partial<IOutputFiles>);
test(configs: IConfigs): Promise<void>;
}
export {};

@@ -84,11 +84,9 @@ "use strict";

correctWriteStream &&
correctWriteStream.write(dfaModuleResult === true
? 'T'
: 'F' +
' ' +
(logicTestResult === true ? 'T' : 'F') +
' ' +
binaryString +
' ' +
'\n');
correctWriteStream.write((dfaModuleResult === true ? 'T' : 'F') +
' ' +
(logicTestResult === true ? 'T' : 'F') +
' ' +
binaryString +
' ' +
'\n');
}

@@ -103,11 +101,9 @@ else {

incorrectWriteStream &&
incorrectWriteStream.write(dfaModuleResult === true
? 'T'
: 'F' +
' ' +
(logicTestResult === true ? 'T' : 'F') +
' ' +
binaryString +
' ' +
'\n');
incorrectWriteStream.write((dfaModuleResult === true ? 'T' : 'F') +
' ' +
(logicTestResult === true ? 'T' : 'F') +
' ' +
binaryString +
' ' +
'\n');
}

@@ -130,84 +126,3 @@ inputWriteStream && inputWriteStream.write(binaryString + '\n');

}
#validateDfaModule(dfa) {
const errors = [];
if (!dfa.testLogic) {
errors.push('testLogic function is required in dfa module');
}
if (!dfa.DFA.label) {
errors.push('Dfa label is required');
}
if (!dfa.DFA.states) {
errors.push('Dfa states is required');
dfa.DFA.states = [];
}
if (!Array.isArray(dfa.DFA.states)) {
errors.push('Dfa states must be an array');
}
if (dfa.DFA.states.length === 0) {
errors.push('Dfa states must be an array of length > 0');
}
dfa.DFA.states.forEach((state) => {
if (!dfa.DFA.transitions[state]) {
errors.push(`Dfa states must reference a state (${state}) that is present in transitions`);
}
});
if (dfa.DFA.start_state === undefined || dfa.DFA.start_state === null) {
errors.push('Dfa start_state is required');
}
if (dfa.DFA.final_states === undefined || dfa.DFA.final_states === null) {
errors.push('Dfa final_states is required');
dfa.DFA.final_states = [];
}
if (!Array.isArray(dfa.DFA.final_states)) {
errors.push('Dfa final_states must be an array');
}
if (dfa.DFA.final_states.length === 0) {
errors.push('Dfa final_states must be an array of length > 0');
}
dfa.DFA.final_states.forEach((state) => {
if (!dfa.DFA.states.includes(state)) {
errors.push(`Dfa final_states must reference a state (${state}) that is present in states`);
}
});
Object.entries(dfa.DFA.transitions).forEach(([transitionKey, transitionValues]) => {
if (!dfa.DFA.states.includes(transitionKey)) {
errors.push(`Dfa transitions must reference a state (${transitionKey}) that is present in states`);
}
if (typeof transitionValues !== 'string' && !Array.isArray(transitionValues)) {
errors.push(`Dfa transitions value must either be string "loop" or a tuple`);
}
if (Array.isArray(transitionValues) && transitionValues.length !== 2) {
errors.push(`Dfa transitions value, when a tuple can contain only 2 items`);
}
if (typeof transitionValues === 'string' && transitionValues !== 'loop') {
errors.push(`Dfa transitions value, when a string can only be "loop"`);
}
if (Array.isArray(transitionValues)) {
transitionValues.forEach((transitionValue) => {
if (!dfa.DFA.states.includes(transitionValue)) {
errors.push(`Dfa transitions value, when a tuple must reference a valid state`);
}
});
}
});
return errors;
}
async test(configs) {
const dfaModulesValidationErrors = [];
let totalDfaModulesValidationErrors = 0;
this.#dfas.forEach((dfaModule) => {
const dfaModuleValidationErrors = this.#validateDfaModule(dfaModule);
console.log(`${colors_1.default.blue.bold(dfaModule.DFA.label)} ${colors_1.default.red.bold(dfaModuleValidationErrors.length.toString())} Errors`);
dfaModuleValidationErrors.forEach((dfaModuleValidationError) => console.log(colors_1.default.red.bold(dfaModuleValidationError)));
totalDfaModulesValidationErrors += dfaModuleValidationErrors.length;
dfaModulesValidationErrors.push({
label: dfaModule.DFA.label,
errors: dfaModuleValidationErrors,
});
console.log();
});
if (dfaModulesValidationErrors.length !== 0) {
console.log(colors_1.default.bold.red(`Total errors ${totalDfaModulesValidationErrors}`));
throw new Error(`Error validating dfa modules`);
}
const writeStreams = this.#dfas.map((dfaModule) => this.#createFileWriteStreams(dfaModule.DFA.label));

@@ -214,0 +129,0 @@ const readStream = configs.type === 'file' ? fs_1.default.createReadStream(configs.filePath) : null;

export * from './BinaryString';
export * from './DfaModule';
export * from './DfaTest';

@@ -14,2 +14,3 @@ "use strict";

__exportStar(require("./BinaryString"), exports);
__exportStar(require("./DfaModule"), exports);
__exportStar(require("./DfaTest"), exports);

@@ -1,2 +0,2 @@

export interface IBinaryDFA {
export interface InputBinaryDFA {
label: string;

@@ -9,5 +9,13 @@ description?: string;

}
export interface TransformedBinaryDFA {
label: string;
description?: string;
start_state: string;
final_states: string[];
states: string[];
transitions: Record<string, [string, string] | 'loop'>;
}
export interface IDfaModule {
testLogic: (binary: string) => boolean;
DFA: IBinaryDFA;
DFA: InputBinaryDFA;
}

@@ -14,0 +22,0 @@ export interface IDfaModuleInfo {

@@ -1,2 +0,2 @@

import { IBinaryDFA } from '../types';
export default function testDfa(DFA: IBinaryDFA, randomBinaryString: string): boolean;
import { TransformedBinaryDFA } from '../types';
export default function testDfa(DFA: TransformedBinaryDFA, randomBinaryString: string): boolean;
{
"name": "dfa-test",
"version": "0.0.3",
"version": "0.0.4",
"description": "A small library to get an insight and test any Deterministic finite automaton(DFA) with binary alphabets",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {

@@ -20,4 +21,12 @@ "prebuild": "del-cli ./dist",

],
"author": "",
"license": "ISC",
"homepage": "https://github.com/Devorein/dfa-test/blob/master/README.md",
"bugs": {
"url": "https://github.com/Devorein/dfa-test/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Devorein/dfa-test.git"
},
"author": "Safwan Shaheer <devorein00@gmail.com>",
"license": "MIT",
"dependencies": {

@@ -32,3 +41,6 @@ "cli-progress": "^3.9.1",

"typescript": "^4.4.4"
},
"publishConfig": {
"access": "public"
}
}

@@ -1,7 +0,11 @@

# Steps
# Introduction
1. Run `npm install`
2. Run `npm run build:watch` in one terminal. This script watches for file changes and compiles ts to js.
3. Run `npm run start` in another terminal to run the program.
A small library to test your DFA against randomly or series generated binary strings.
## Writing a DFA
```js
```
Take a look at the [examples](./examples) folder to understand how to write a dfa test and use this package.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc