forked from wonderflow-bv/string-calculator-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
51 lines (35 loc) · 1.21 KB
/
index.test.js
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
const { add } = require('.')
const test = require('ava')
test('add() should return 0 for empty string', t => {
const result = add('')
t.is(result, 0)
})
test('add() should return digit if only one number provided', t => {
const result = add('1')
t.is(result, 1)
})
test('add() should return sum of 2 digits if two number provided separated by ,', t => {
const result = add('1,2')
t.is(result, 3)
})
test('add() should return sum of n digits if n numbers provided separated by ,', t => {
const result = add('5,6,10,100')
t.is(result, 121)
})
test('add() should return sum of n digits if n numbers provided separated by , or \n', t => {
const result = add('5,6,10\n100,12\n9')
t.is(result, 142)
})
test('add() should return sum of n digits if n numbers provided separated by , or \n or custom delimeter', t => {
const result = add('//;\n5;6;10;100;12;9')
t.is(result, 142)
})
test('add() throws if negative numbers', t => {
const negativeNumber = -5
const error = t.throws(() => add(`1,5,10,${negativeNumber}`))
t.is(error.message, `negatives not allowed: ${negativeNumber}`)
})
test('add() should ignore number gt 1000', t => {
const result = add('5,1001,999,10000')
t.is(result, 1004)
})