StringCalculator kataKata
- The method can take 0, 1, or 2 numbers and will return their sum.
- Example inputs: "", "1", or "1,2"
- Start with the simplest test case of an empty string. Then 1 number. Then 2 numbers.
- Remember to refactor after each passing test.
- Example: “1\n2,3” should return 6
- Example: “1,\n” is invalid, but you don’t need a test for this case.
- Only test correct inputs – there is no need to deal with invalid inputs for this kata.
- To change the delimiter, the beginning of the string will contain a separate line that looks like this: "//[delimiter]\n[numbers]"
- Example: "//;\n1;2" should return 3 (the delimiter is ;)
- This first line is optional; all existing scenarios (using , or \n) should work as before.
5.Calling Add with a negative number will throw an exception "Negatives not allowed: "listing all negative numbers that were in the list of numbers
- Example “-1,2” throws "Negatives not allowed: -1"
- Example “2,-4,3,-5” throws "Negatives not allowed: -4,-5"
- Example: “1001,2” returns 2