Let’s write a calculator that takes a string and evaluates it as if it were a calculation. The idea is to implement it a bit at a time with tests, and see where the design ends up. The kata description contains quite a detailed list of requirements and examples, written in the order you should implement them in.
Note: if your language has a built-in ‘eval’ or another kind of runtime evaluation of string expressions - you’re not allowed to use it in your solution to this exercise!
Let’s start with the basics! If you give your String Calculator a single integer, just return that integer.
If you get two integers separated by a + sign, add them together.
Also handle minus signs.
Whitespace should be ignored
I’m sure you can think of more steps to add here. Multiplication, floating point numbers, parentheses… Try to continue in the same style though. Add one small thing at a time with a test and just enough code to make it work, while all the existing tests also keep working.