This exercise is based off the work of Roy Osherove
- Do not read ahead
- Do one task at a time
- Refactor as necessary
- Do not handle invalid inputs
- Check in often
- Tests are your friends
Clone the branch from here
Create and push a branch under attempts/
now. Ideally you can call it <first name>_<last name>
(eg. attempts/philippe_castonguay
)
You will be building a String Calculator. The initial branch contains the following projects:
- Product - The String Calculator you will be developing, with the initial function stub
- Product.Tests - An XUnit test file with one failing test
- Product.CLI - A simple console application that will run the calculator and show the results
Only expand the details once you have completed the previous step, to avoid looking ahead
0. Base case
Start with the base case.Eg.
"" → 0
1. Loneliest
When one number is passed, return that number for the sumEg.
"1" → 1
"10" → 10
2. Basics
When two numbers are passed, separated by a plus '+', return their sumEg.
"1+1" → 2
"12+34" → 36
3. N
Allow any number of numbers to be passed, and add ',' as a delimiterEg.
"1,2,3" → 6
"1,1,1,1,1" → 5
4. NL
Allow the new line character (\n) to be used as a delimiter as wellEg.
"1\n2" → 3
5. Custom
Allow optional custom delimiters, in the format of "//{delimiter}{numbers}" (It should continue to work without the delimiters)Eg.
"//;1;2" → 3
6. Negative
When a negative is passed, throw an Exception with the message "Negatives not allowed ({number})", where number is the first negative number that was encounteredEg.
"-1" → "Negatives not allowed (-1)"
7. Numerous
When multiple negatives are passed, return the comma-separated list of all the negatives in the order they were presented, instead of just the first oneEg.
"-1,-2" → "Negatives not allowed (-1,-2)"
8. Mille
Ignore numbers greater than 1000Eg.
"1,1005" → 1
9. Delimited
Allow for delimiters of any length, using the format "//[{delimiter}]{numbers}". (The previous delimiter method should continue to work)Eg.
"//[***]1***2***3" → 6
10. Unlimiated
Allow for multiple long delimiters, using the format "//[{delimiter1}][{delimiter2}][{...}]{numbers}".Eg.
"//[*][%]1*2%3" → 6
11. Revision
Ensure that you can use multiple and long delimitersEg.
"//[***][%%%]1***2%%%3" → 6