πŸ“¦ itsmadhusudhan / tdd-kata

πŸ“„ README.md Β· 60 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60# TDD Assessment

This project uses bun to run, bundle and test the code.

To install dependencies:

```bash
bun install
```

To run tests:

```bash
bun run test
```

To bundle the code:

```bash
bun run bundle
```

## The Problem:

### Steps:

1. 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

2. Allow the `add` method to handle any amount of numbers.

3. Allow the `add` method to handle new lines between numbers (instead of commas). (`"1\n2,3"` should return `6`)

4. 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`.

5. Calling add with a negative number will throw an exception: "negative numbers not allowed `<negative_number>`".

6. If there are multiple negative numbers, show all of them in the exception message, separated by commas.

7. Numbers bigger than 1000 should be ignored, so adding 2 + 1001 = 2

8. Delimiters can be of any length with the following format: β€œ//[delimiter]\n” for example: β€œ//[***]\n1***2***3” should return 6

9. Allow multiple delimiters like this: β€œ//[delim1][delim2]\n” for example β€œ//[*][%]\n1*2%3” should return 6.

10. Allow multiple delimiters with length longer than one char like this: β€œ//[*][%]\n1*2%3” should return 6.