Skip to content

Repository files navigation

TDD String Algorithms Practice

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.

Project Overview

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.

Technologies Used

  • JavaScript (ES Modules)
  • Jest - Testing framework
  • Node.js

Implemented Algorithms

Core String Functions

  • 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 case
    • toStylesTypes & toStylesTypesTwo - Converts between kebab-case, snake_case, and camelCase

Advanced Algorithms

  • Longest Substring Without Repeating Characters

    • longestSub - Sliding window approach
    • findLongestSubstring - Optimized implementation with character indexing
  • Substring Occurrence Counting

    • occurenceR - Counts occurrences of a substring using sliding window
    • occurences - Alternative implementation with nested loops

Utility Functions

  • 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

Project Structure

├── 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

Development Approach

This project follows Test-Driven Development principles:

  1. Red: Write failing tests first
  2. Green: Implement minimal code to pass tests
  3. 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

Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Installation

# Clone the repository
git clone <repository-url>
cd tdd_study

# Install dependencies
npm install

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

Test Coverage

The 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

Key Learning Outcomes

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

Notable Implementations

Sliding Window Technique

The longest substring algorithms demonstrate the sliding window pattern, with two different approaches showing performance trade-offs.

Unicode-Aware Processing

All string functions properly handle Unicode characters, including:

  • Emojis and special characters
  • Diacritical marks (accents, umlauts, etc.)
  • Case conversion across different languages

Multiple Solution Approaches

Some algorithms have multiple implementations (e.g., toStylesTypes vs toStylesTypesTwo) allowing comparison of different coding styles and efficiencies.

Future Enhancements

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.

About

A comprehensive Test-Driven Development (TDD) project implementing various string algorithms in JavaScript without AI help. Features palindrome detection, anagram checking, case conversion, longest substring algorithms, and more. Built with Jest for thorough testing, emphasizing clean code and algorithmic problem-solving

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages