dsa-gen
v1.0.0
Published
Smart toolkit for generating test cases, debugging algorithms, and analyzing performance.
Downloads
14
Maintainers
Readme
🚀 Smart DSA Toolkit – Debug Algorithms Like a Pro
A powerful toolkit to generate test cases, detect bugs, minimize failing inputs, and analyze algorithm performance.
⚡ 10-Second Demo
1. Compare your solutions and find the absolute smallest failing edge case:
npx dsa-gen compare brute.js optimized.js --preset=binary-searchOutput:
❌ MISMATCH DETECTED
────────────────────────────
Input : [2, 1, 2]
Expected : 6
Got : 5
────────────────────────────
🔍 Minimizing failing test case...
✅ Smallest failing case found!
❌ Minimal Failing Input
────────────────────────────
[2, 1, 2]
Expected : 6
Got : 5
────────────────────────────
Seed: 42
✅ Saved failing case to ./failing_case.json❓ The Problem
- Debugging large inputs is hard: When your Leetcode or CP solution fails on a 10,000-element array, finding the exact issue is nearly impossible.
- Random test generators are dumb: Simple random outputs naturally miss critical edge cases (negatives, duplicates, boundaries).
- Benchmarking is tedious: Setting up
performance.now()loops with varyingNlengths gets repetitive.
✅ The Solution
This toolkit changes the game by:
- Generating smart test cases mapped to algorithm constraints (e.g., sorting, binary search, graphs).
- Finding bugs automatically by cross-testing your optimized code against a brute-force approach.
- Minimizing failing cases (Delta-Debugging) automatically. Once it fails, it shrinks the array/string down to the absolute smallest reproducible failure.
- Benchmarking performance gracefully to dynamically estimate Big-O complexities.
🔥 Features List
- 🧠 Smart test case generation (Arrays, Strings, Trees, Graphs, Matrices, Numbers)
- 🎲 Problem-aware edge cases built-in
- 🔬 Automatic minimizer (Killer Feature)
- ⚖️ Comparator (brute vs optimized tests)
- ⏱️ Benchmarking with O() complexity estimation
- 🪄 Interactive CLI wizard with colorful outputs (
chalk&inquirer) - 💾 Save / Load / Replay test suites
- 🎚️ Presets & Difficulty Levels (easy, medium, hard)
📦 Installation
Install globally to use the CLI anywhere:
npm install -g dsa-genOr install as a dev dependency to use it programmatically in your testing workflow:
npm install dsa-gen --save-dev🛠 Usage Examples
CLI Command List
You can trigger the interactive wizard simply using:
npx dsa-genOtherwise, invoke tools directly:
npx dsa-gen generate– Open test case generation wizard.npx dsa-gen replay– Replays standard./failing_case.jsonconfig.npx dsa-gen compare– Trigger programmatic API info notice.npx dsa-gen benchmark– Trigger programmatic API info notice.npx dsa-gen visualize– Visualizes data structures as Ascii representations.
Programmatic Usage
1. Debugging with compareSolutions & Auto-Minimizer:
import { compareSolutions, generateArray } from 'dsa-gen';
const bruteForce = (arr) => { /* correct, slow logic */ };
const optimizedBuggy = (arr) => { /* fast logic w/ bug */ };
// Setup a generator using our difficulty presets
const generatorFn = () => [ generateArray({ size: 100, difficulty: 'hard' }) ];
compareSolutions(bruteForce, optimizedBuggy, {
generatorFn,
iterations: 1000,
savePath: './failing_case.json', // Will export the minimal array here
verbose: true
});2. Educational Benchmarking runBenchmark:
import { runBenchmark, generateString } from 'dsa-gen';
const algorithm = (str) => { /* ... */ };
const generatorFn = (n) => [ generateString({ length: n }) ];
runBenchmark(algorithm, generatorFn, [10, 100, 1000, 10000]);Output visually scales and automatically predicts O(N), O(N log N), O(1), or O(N^2).
🎯 Target Use Cases
- Debugging algorithms: Find the exact edge cases where an optimized logic fails.
- Interview preparation: Practice recognizing edge cases and testing tree/graph manipulations.
- Competitive programming: Speed up testing locally before pushing to platforms like Codeforces.
- Performance testing: Quickly assert
O(N)constraints before submission.
