A comprehensive Test-Driven Development (TDD) project focused on implementing and testing various string manipulation algorithms. This project was created to practice TDD methodology without AI assistance, emphasizing clean code, thorough testing, and algorithmic problem-solving.
This repository contains implementations of common string algorithms, developed using a strict TDD approach. Each algorithm includes comprehensive test suites that cover edge cases, Unicode handling, and performance considerations.
- JavaScript (ES Modules)
- Jest - Testing framework
- Node.js
-
Palindrome Detection (
isPalindrome)- Checks if a string reads the same forwards and backwards
- Handles case insensitivity, whitespace, punctuation, and Unicode characters
- Supports diacritics and emojis
-
String Reversal (
reverseString)- Reverses the order of characters in a string
- Handles Unicode characters correctly
-
Anagram Detection (
isAnagram)- Determines if two strings contain the same characters with the same frequencies
- Case-insensitive with punctuation and whitespace normalization
-
Case Conversion
toTitleCase- Converts strings to title casetoStylesTypes&toStylesTypesTwo- Converts between kebab-case, snake_case, and camelCase
-
Longest Substring Without Repeating Characters
longestSub- Sliding window approachfindLongestSubstring- Optimized implementation with character indexing
-
Substring Occurrence Counting
occurenceR- Counts occurrences of a substring using sliding windowoccurences- Alternative implementation with nested loops
-
Diacritic Normalization (
normalizeDiacritics)- Removes diacritical marks from strings using Unicode normalization
-
String Truncation (
truncateWithEllipsis)- Truncates strings to specified length with ellipsis
- Handles Unicode characters properly
-
Word Counting (
wordCount)- Counts words in a string using regex patterns
├── index.js # Primary algorithm implementations
├── index_2.js # Alternative implementations
├── *.test.js # Comprehensive test suites
├── jest.config.mjs # Jest configuration
├── package.json # Project dependencies and scripts
└── jsconfig.json # JavaScript project configuration
This project follows Test-Driven Development principles:
- Red: Write failing tests first
- Green: Implement minimal code to pass tests
- Refactor: Improve code while maintaining test coverage
Each algorithm implementation includes:
- Multiple test cases covering normal and edge cases
- Unicode and internationalization support
- Performance considerations
- Clean, readable code
- Node.js (v14 or higher)
- npm or yarn
# Clone the repository
git clone <repository-url>
cd tdd_study
# Install dependencies
npm install# Run all tests
npm test
# Run tests in watch mode
npm run test:watchThe project includes comprehensive test coverage for:
- Basic functionality
- Edge cases (empty strings, single characters, etc.)
- Unicode handling (emojis, diacritics, international characters)
- Case sensitivity
- Performance with various input sizes
Through this TDD practice project, the following concepts were explored:
- Algorithm Design: Implementing efficient solutions for string problems
- Test-Driven Development: Writing tests before implementation
- Unicode Handling: Proper support for international characters
- Performance Optimization: Comparing different algorithmic approaches
- Code Refactoring: Improving implementations while maintaining functionality
- Edge Case Handling: Comprehensive coverage of boundary conditions
The longest substring algorithms demonstrate the sliding window pattern, with two different approaches showing performance trade-offs.
All string functions properly handle Unicode characters, including:
- Emojis and special characters
- Diacritical marks (accents, umlauts, etc.)
- Case conversion across different languages
Some algorithms have multiple implementations (e.g., toStylesTypes vs toStylesTypesTwo) allowing comparison of different coding styles and efficiencies.
Potential areas for expansion:
- Additional string algorithms (Levenshtein distance, string compression, etc.)
- Performance benchmarking
- Integration with other data structures
This project serves as a practical demonstration of TDD principles applied to algorithmic problem-solving in JavaScript.