Skip to content

Latest commit

 

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Calculator – TDD Kata (Dart)

This repository contains a robust implementation of the String Calculator Kata using Test-Driven Development (TDD) in Dart. The project follows an incremental approach to string parsing, validation, and mathematical logic.


📌 Project Overview

The StringCalculator class provides a flexible add method capable of processing strings with various delimiters, handling edge cases, and enforcing specific mathematical constraints.

The codebase is:

  • Fully unit-tested
  • Explicitly documented using DartDoc (///) comments
  • Designed for readability, maintainability, and robustness

This implementation strictly follows the Red → Green → Refactor cycle, ensuring every feature is backed by a test and clearly documented.


🧪 What is TDD and TDD Process?

Test-Driven Development (TDD):

This project was developed using strict TDD discipline:

  • Each feature starts with a failing test (RED)
  • Minimal implementation added to pass the test (GREEN)
  • Code improved without changing behavior (REFACTOR)

This process ensures:

  • High test coverage
  • Clean, maintainable code
  • Confidence in refactoring
  • Clear traceability between requirements, tests, and implementation

The commit history demonstrates the full RED–GREEN–REFACTOR progression.

🚀 Supported Features

Based on the implemented test suite, the calculator supports the following:

Feature Input Example Result
Empty String "" 0
Single Number "5" 5
Sum of Two Numbers "1,2" 3
Multiple Numbers "1,2,3,4" 10
Newline Delimiters "1\n2,3" 6
Custom Delimiters "//;\n1;2" 3
Negative Numbers "1,-2,3" Throws Exception
Upper Bound Limit "2,1001" 2 (Numbers > 1000 ignored)
Multi-character Delimiters "//[***]\n1***2***3" 6
Multiple Delimiters "//[*][%]\n1*2%3" 6
Empty Tokens Between Delimiters "1,,3" 4
Invalid Input "1,a,3" Throws Exception

🧾 Code Documentation

All public classes and methods are documented using DartDoc (///) syntax.

The documentation clearly describes:

  • Class responsibilities
  • Method behavior
  • Supported input formats
  • Parameters and return values
  • Thrown exceptions
  • Usage examples

Example (from source code):

/// A calculator that adds numbers from a string input.
///
/// Supports multiple delimiters and custom delimiter syntax.
/// Numbers greater than 1000 are ignored.
/// Throws an exception if negative numbers are found.
class StringCalculator {
  /// Adds numbers in the given string and returns the sum.
  ///
  /// Parameters:
  /// - [numbers]: A string containing numbers separated by delimiters
  ///
  /// Returns:
  /// - The sum of all valid numbers (≤ 1000)
  ///
  /// Throws:
  /// - [Exception] if negative or invalid numbers are present
  int add(String numbers) { ... }
}

🛠️ Installation & Usage

1. Prerequisites

Ensure you have the Dart SDK installed on your machine.

2. Run Tests

To verify the implementation against the test suite, run:

dart test
or
fvm dart test

🧪 Usage Example

import 'package:string_calculator_tdd/string_calculator.dart';

void main() {
  final calc = StringCalculator();

  print(calc.add(""));              // 0
  print(calc.add("1,2,3"));         // 6
  print(calc.add("//;\n1;2"));      // 3
  print(calc.add("2,1005"));        // 2 (1005 is ignored)
}

screenshots/ ├── tests_passing.png ├── commit_history.png └── test_coverage.png (optional)


🖥 tests passing 🧪 commit history 🧪 test coverage


Author

Parth Pitroda
GitHub: https://github.com/hiopitroda Date: 24 January 2026 Assessment: Incubyte TDD Kata


About

String Calculator TDD Kata demonstrating Test-Driven Development in Dart

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages