TDD Assessment
This project uses bun to run, bundle and test the code.
To install dependencies:
bun install
To run tests:
bun run test
To bundle the code:
bun run bundle
The Problem:
Steps:
- Create a simple String calculator with a method signature like this:
int add(string numbers)
Input: a string of comma-separated numbers
Output: an integer, sum of the numbers
Examples:
Input: ββ, Output: 0
Input: β1β, Output: 1
Input: β1,5β, Output: 6
- Allow the
add method to handle any amount of numbers.
- Allow the
add method to handle new lines between numbers (instead of commas). ("1\n2,3" should return 6)
- Support different delimiters:
To change the delimiter, the beginning of the string will contain a separate line that looks like this:
"//[delimiter]\n[numbersβ¦]". For example,
"//;\n1;2" where the delimiter is
";" should return
3.
- Calling add with a negative number will throw an exception: "negative numbers not allowed
<negative_number>".
- If there are multiple negative numbers, show all of them in the exception message, separated by commas.
- Numbers bigger than 1000 should be ignored, so adding 2 + 1001 = 2
- Delimiters can be of any length with the following format: β//[delimiter]\nβ for example: β//[]\n12***3β should return 6
- Allow multiple delimiters like this: β//[delim1]\nβ for example β//[]\n12%3β should return 6.
- Allow multiple delimiters with length longer than one char like this: β//[]\n12%3β should return 6.