Created
July 20, 2012 15:00
-
-
Save coreyhaines/3151178 to your computer and use it in GitHub Desktop.
String Calculator Kata Steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*credit to Roy Osherove http://osherove.com/tdd-kata-1/ * | |
1, Create a simple String calculator with a function #add | |
- The method can take 0, 1 or 2 numbers and will return their sum (for an empty string, it will return 0) for example "" or "1" or "1,2" | |
- Start with the simplest test case of an empty string and move to 1 and 2 numbers | |
- Remember to solve things as simple as possible so that you force yourself to write tests you did not think about | |
- Remember to refactor after EACH passing test | |
2, Allow the add method to handle an unknown amount of numbers | |
3, Allow the add method to handle new lines between numbers (instead of commas) | |
- The following input is ok: "1\n2,3" (will equal 6) | |
- The following input is NOT ok: "1,\n" (don't worry about proving it, no need to check for this) | |
4, Support different delimiters | |
- to change a delimiter, the beginning of the string will contain a separate line that looks like this: "//[delimiter]\n[numbers]" for example "//;\n1;2" should return 3 where the default delimiter is ';' | |
- the first line is optional. all existing scenarios should still be supported. | |
5, Call add with a negative number will raise an exception "negatives not allowed" - and the negative that was passed. If there are multiple negatives, show all of them in the exception message | |
*bonus* | |
6, Numbers bigger than 1000 should be ignored, so adding "2,1001" == 2 | |
7, Delimiters can be of any length with the following format: "//[delimiter]\n" for example: "//[***]\n1***2***3" should return 6 | |
8, Allow multiple delimiters like this: "//[delim1][delim2]\n" for example "//[*][%]\n1*2%3" should return 6 | |
9, make sure you can also handle multiple delimiters with lengths longer than one char | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment