|
| 1 | +# String Calculator Kata |
| 2 | + |
| 3 | +From: http://osherove.com/tdd-kata-1/ |
| 4 | + |
| 5 | +1. Create a simple String calculator with a method int Add(string numbers). |
| 6 | + 1. The method can take 0, 1 or 2 numbers, and will return their sum (for an empty |
| 7 | + string it will return 0). For example "" or "1" or "1,2" |
| 8 | + 2. Start with the simplest test case of an empty string and move to 1 and |
| 9 | + two numbers |
| 10 | + 3. Remember to solve things as simply as possible so that you force yourself |
| 11 | + to write tests you did not think about |
| 12 | + 4. Remember to refactor after each passing test |
| 13 | +2. Allow the Add method to handle an unknown amount of numbers |
| 14 | +3. Allow the Add method to handle new lines between numbers (instead of commas). |
| 15 | + 1. the following input is ok: "1\n2,3" (will equal 6) |
| 16 | + 2. the following input is NOT ok: "1,\n" (not need to prove it - just |
| 17 | + clarifying) |
| 18 | +4. Support different delimiters. |
| 19 | + 1. To change a delimiter, the beginning of the string will contain a |
| 20 | + separate line that looks like this: `//[delimiter]\n[numbers...]`, for |
| 21 | + example `//;\n1;2` should return three where the default delimiter is `;` |
| 22 | + . |
| 23 | + 2. the first line is optional. all existing scenarios should still be |
| 24 | + supported |
| 25 | +5. Calling Add with a negative number will throw an exception "negatives not |
| 26 | + allowed" - and the negative that was passed.if there are multiple negatives, |
| 27 | + show all of them in the exception message |
| 28 | +6. Numbers bigger than 1000 should be ignored, so adding 2 + 1001 = 2 |
| 29 | +7. Delimiters can be of any length with the following format: `//[delimiter]\n` |
| 30 | + for example: `//[***]\n1***2***3` should return 6 |
| 31 | +8. Allow multiple delimiters like this: `//[delim1][delim2]\n` for example |
| 32 | + `//[*][%]\n1*2%3` should return 6. |
| 33 | +9. make sure you can also handle multiple delimiters with length longer than one |
| 34 | + char |
| 35 | + |
| 36 | + |
0 commit comments