String Calculator

Problem Description

First and foremost, try NOT to read ahead. String Calculator is structured as a series of requirements and addressing them in order should prompt you to do some refactoring along the way. The goal here is to create a simple calculator which performs its operations on string input.

Release 1

  • Create a simple calculator which performs addition operations on up to two numbers
  • Your language may differ but you’re looking for a method signature that looks like this: int Add(string numbers)
  • Separate your input values with commas and return their sum. EG: an empty string, 1, or 1,2 will return 0, 1, and 3 respectively.

Hints

  • Start with the simplest test case of an empty string and move on from there.
  • Look for the most degenerate test cases and start there. By starting simple and adding supporting tests first you’ll find edge cases.
  • Remember the “refactor” part of the “red, green, refactor” cycle.

Release 2

  • Allow the Add method to handle an indeterminate amount of numbers
  • EG: 1,2,3 -> 6

Release 3

  • Allow the Add method to handle new lines \n between numbers instead of commas
  • EG: 1\n2,3 -> 6

Release 4

  • Add support for user-supplied delimiters.
  • Users can provide input as follows: //[delimiter]\n[input string]
  • EG: //&\n1&2&3 -> 6

Release 5

  • Calling Add with a negative number provides a useful error message
  • The message should contain ALL of the negative numbers in the input string
  • EG: 1,-2,-3,4 -> Negatives not allowed: -2, -3

Release 6

  • Numbers bigger than 1000 should be ignored
  • EG: 1001,2 -> 2

Release 7

  • Delimiters can be of ANY length if users use the // method outlined in Release 4 and enclose them in square brackets []
  • EG: //[***]\n1***2***3 -> 6

Release 8

  • Handle multiple delimiters using the format in Release 7
  • EG: //[*][&]\n1&2*3 -> 6

Release 9

  • Make sure you can support multi-character delimiters (release 7) in your multi-delimiter feature (release8)