palekh / fuzzing Goto Github PK
View Code? Open in Web Editor NEW๐ฐ Tool set for fuzz and stress testing your functions!
License: MIT License
๐ฐ Tool set for fuzz and stress testing your functions!
License: MIT License
It was unclear how to run the fuzzer - I eventually figured out it should be compiled with tsc
and run with node
:
import { chunkStringIntoFours } from "../src/chunkStringIntoFours";
function chunkStringIntoFoursForLoop(input: string): string {
if (typeof input !== "string") {
throw Error("chunkStringIntoFours can only chunk strings");
}
if (/[\uD800-\uDBFF]/.test(input)) {
throw Error("chunkStringIntoFours does not support non BMP strings");
}
if (/[\r\n]/.test(input)) {
throw Error("chunkStringIntoFours does not support whitespace");
}
const array = [];
// make input.length / 4 strings that contain 4 characters
for (let i = 0; i < input.length; i++) {
if (i % 4 === 0) {
array[Math.floor(i / 4)] = input[i];
} else {
array[Math.floor(i / 4)] += input[i];
}
}
return array.join(" ");
}
import { fuzz } from "fuzzing";
const errors = fuzz((input) => {
try {
if (chunkStringIntoFours(input) !== chunkStringIntoFoursForLoop(input)) {
throw Error("chunkStringIntoFours did not output the same as chunkStringIntoFoursForLoop");
}
} catch (e: unknown) {
if (
e instanceof Error &&
["chunkStringIntoFours can only chunk strings"].includes(e.message)
) {
// no error
return true;
}
throw e;
}
})
.string()
.errors();
console.log(errors);
Example script that I made that imports the function to be tested and then I have an npm script:
{
"scripts": {
"fuzz": "tsc --incremental && node ./dist/fuzz/chunkStringIntoFours.js",
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.