Learning Go through a TDD Code Kata
Developed by Roy Osherove - http://osherove.com/tdd-kata-1
The goal of this exercise is to see how far you can get in 30 minutes. Write a test before implementing any code. Remember to solve things as simply as possible so that you force yourself to write tests you did not think about. Remember to refactor after each passing test
Developed by Roy Osherove - http://osherove.com/tdd-kata-1
The goal of this exercise is to see how far you can get in 30 minutes. Write a test before implementing any code. Remember to solve things as simply as possible so that you force yourself to write tests you did not think about. Remember to refactor after each passing test
The method can take 0, 1 or 2 numbers, and will return their sum. For example:
- Add(“”) should return 0
- Add(“2112”) should return 2112
- Add(“2,3”) should return 5
- The following input is ok: “1\n2,3” (will equal 6)
- The following input is NOT ok: “1,\n” (no need to prove it - just clarifying)
- 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 three where the default delimiter is ‘;’ - All existing tests should still be supported
Step 5: Calling Add with a negative number will throw an exception “negatives not allowed” and the negative that was passed
- If there are multiple negatives, show all of them in the exception message
- Adding 2 + 1001 = 2
- For example:
“//[***]\n1***2***3”should return 6
- For example:
“//[*][%]\n1*2%3”should return 6 - Make sure you can also handle multiple delimiters with length longer than one char