-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.test.js
More file actions
52 lines (51 loc) · 1.92 KB
/
add.test.js
File metadata and controls
52 lines (51 loc) · 1.92 KB
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
const {add} = require('./index')
describe('Add Test', () => {
describe('Simple Test - Part 1', () => {
it('should return 0 when input is empty string', () => {
expect(add('')).toBe(0);
});
it('should add for comma seperated string', () => {
expect(add('1,2,3')).toBe(6);
});
});
describe('Ignore new line - Part 2', () => {
it('should ignore new line indicator before comma', () => {
expect(add('1\n,2,3')).toBe(6);
});
it('should ignore new line indicator after comma', () => {
expect(add('1,\n2,3')).toBe(6);
});
it('should ignore multiple new line indicators', () => {
expect(add('\n1,\n2,\n3')).toBe(6);
});
});
describe('Support custom delimiters - Part 3', () => {
it('should support seperate semicolon delimiters ', () => {
expect(add('//;\n1;3;4')).toBe(8);
});
it('should support dollar sign delimiters ', () => {
expect(add('//$\n12$15$32')).toBe(59);
});
it('should support @ sign delimiters ', () => {
expect(add('//@\n2@3@8')).toBe(13);
});
it('should raise an exception if a negative number exists in the list ', () => {
expect(() => add('//@\n-2@3@8'))
.toThrowError(new Error('Negatives not allowed: -2,3,8'));
});
});
describe('Bonus', () => {
it('should ignore values greater than 1000', () => {
expect(add('1001,2')).toBe(2);
});
it('should accept arbitrary length delimiters', () => {
expect(add("//***\n1***2***3")).toBe(6);
});
it('should accept multiple delimiters', () => {
expect(add("//!,$\n1!2$3")).toBe(6);
});
it('should accept multiple and arbitrary length delimiters', () => {
expect(add("//!!!!!,..\n1!!!!!2..3")).toBe(6);
});
})
});