Skip to content

azharsheikh-ruby/string-calculator-tdd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Calculator TDD Kata

Overview

This is my solution to the Incubyte String Calculator TDD Kata.
The goal of the kata is to implement a string calculator with the following capabilities:

  • Return 0 for an empty string.
  • Return the sum of numbers provided as a string.
  • Support one or more numbers separated by commas or newlines.
  • Support custom delimiters specified in the format: //[delimiter]\n[numbers].
  • Throw an exception for negative numbers, listing all negatives.

This implementation was built following the TDD approach, with incremental tests and refactoring.


Features Implemented

  1. Empty String
    calculator.add("") # => 0
  2. Single Number
    calculator.add("5") # => 5
  3. Multiple Numbers
    calculator.add("1,2,3") # => 6
  4. Newline as Delimiter
    calculator.add("1\n2,3") # => 6
  5. Custom Delimiter
    calculator.add("//;\n1;2") # => 3
  6. Negative Number Handling
    calculator.add("-1,2") 
    # Raises: "negative numbers not allowed -1"
    
    calculator.add("2,-4,3,-5") 
    # Raises: "negative numbers not allowed -4,-5"

How to Run

  1. Install dependencies (RSpec): gem install rspec

  2. Run tests: rspec spec/string_calculator_spec.rb --format documentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages