Test Framework
This project uses Jest as the testing framework with SWC for fast TypeScript transpilation. Every data structure and algorithm includes comprehensive test coverage.Running All Tests
To run the complete test suite:- Compile all TypeScript files using
tsc - Run all tests with Jest
- Display a summary of test results
The
npm test script is defined in package.json as "test": "tsc && jest"Running Specific Tests
Jest provides powerful filtering options to run specific tests without executing the entire suite. Use the--testNamePattern (or -t) flag to target tests by name.
By Data Structure
Run all tests for a specific data structure:By Algorithm
Run all tests for a specific algorithm:By Problem Number
Run a specific coding problem:Running Tests by File
You can also run tests from specific files:Test Output
Successful test runs will display:Watch Mode
Run tests in watch mode to automatically re-run tests when files change:- a - Run all tests
- f - Run only failed tests
- p - Filter by filename pattern
- t - Filter by test name pattern
- q - Quit watch mode
Test Coverage
Generate a test coverage report:coverage/ directory.
Understanding Test Files
The project contains three types of test files:- Implementation Tests
- Problem Tests
- Design Technique Tests
Files ending in These tests verify that the implementation works correctly.
.test.ts contain unit tests for the data structure or algorithm implementation.Jest Configuration
The Jest configuration is defined injest.config.js:
Advanced Jest Options
Run Tests in Parallel
Jest runs tests in parallel by default. To control the number of workers:Verbose Output
Display individual test results:Clear Cache
If you encounter issues, clear Jest’s cache:Update Snapshots
If using snapshot tests (not common in this project):Debugging Tests
To debug tests in Node.js:chrome://inspect in Chrome and click “inspect” on the Node process.
Continuous Integration
This project uses GitHub Actions for continuous integration. The CI pipeline runs all tests on every push and pull request to ensure code quality. You can view the CI status badge in the README:Common Test Patterns
Testing Data Structures
Data structure tests typically verify:- Initialization and construction
- Adding and removing elements
- Searching and accessing elements
- Edge cases (empty structure, single element, etc.)
- Performance characteristics
Testing Algorithms
Algorithm tests typically verify:- Correct output for various inputs
- Edge cases (empty arrays, single elements, etc.)
- Sorted vs. unsorted inputs
- Duplicate elements
- Performance on large datasets
Testing Problem Solutions
Problem tests include:- Multiple solution approaches
- Time and space complexity in comments
- Expected output validation
- Edge case handling
Next Steps
Data Structures
Explore the implemented data structures
Algorithms
Learn about sorting, searching, and graph algorithms