String Calculator Kata v1
String Calculator Kata v1
http://osherove.com/kata
Before you start:
■ Try not to read ahead .
■ Do one task at a time. The trick is to learn to work incrementally.
■ Make sure you only test for correct inputs. there is no need to test for invalid inputs for
this kata
■ Test First!
String Calculator
3. Allow the Add method to handle new lines between numbers (instead of commas).
1. the following input is ok: “1\n2,3” == 6
2. the following is INVALID input so do not expect it : “1,\n” (not need to write a
test for it)
5. Calling Add with a negative number will throw an exception “negatives not allowed” -
and the negative that was passed.
6. If there are multiple negatives, show all of them in the exception message
8. (.NET Only) Using TDD, Add an event to the StringCalculator class named
public event Action<string, int> AddOccured ,
that is triggered after every Add() call.
Hint:
Create the event declaration first:
then write a failing test that listens to the event
and proves it should have been triggered when calling Add().
Hint 2:
Example:
string giveninput = null;
sc.AddOccured += delegate(string input,
int result)
{
giveninput = input;
};
9. Numbers bigger than 1000 should be ignored, for example:
2 + 1001 == 2
12. make sure you can also handle multiple delimiters with length longer than one char
for example
“//[**][%%]\n1**2%%3” == 6.