-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
59 lines (51 loc) · 1.88 KB
/
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
52
53
54
55
56
57
58
59
/*!
* array-sum <https://github.com/jonschlinkert/array-sum>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License
*/
var assert = require('assert');
var arraySum = require('./');
it('should return 0 when the value is undefined.', function () {
assert.equal(arraySum(), 0);
});
it('should return 0 when an empty array is passed.', function () {
assert.equal(arraySum([]), 0);
});
it('should add the numbers in the array.', function () {
assert.equal(arraySum([1, 2, 3, 4, 5]), 15);
});
it('should add the numbers in the array.', function () {
assert.equal(arraySum(['-1.1', 10]), 8.9);
assert.equal(arraySum(['0', 1]), 1);
assert.equal(arraySum(['012', 1]), 13);
assert.equal(arraySum(['0xff', 1]), 256);
assert.equal(arraySum(['1', 1]), 2);
assert.equal(arraySum(['1.1', 1]), 2.1);
assert.equal(arraySum(['10', 1]), 11);
assert.equal(arraySum(['10.10', 1]), 11.10);
assert.equal(arraySum(['100', 1]), 101);
assert.equal(arraySum(['5e3', 1]), 5001);
assert.equal(arraySum(['Infinity', 5]), 5);
assert.equal(arraySum([-1.1, 10]), 8.9);
assert.equal(arraySum([0, 1]), 1);
assert.equal(arraySum([0xff, 1]), 256);
assert.equal(arraySum([1, 1]), 2);
assert.equal(arraySum([1.1, 1]), 2.1);
assert.equal(arraySum([10, 1]), 11);
assert.equal(arraySum([10.10, 1]), 11.10);
assert.equal(arraySum([100, 1]), 101);
assert.equal(arraySum([5e3, 1]), 5001);
assert.equal(arraySum([Infinity, 1]), 1);
assert.equal(arraySum([parseFloat('012'), 1]), 13);
assert.equal(arraySum([parseInt('25a'), 1]), 26);
});
it('should work with strings', function () {
assert.equal(arraySum(['1', '2', '3', '4', '5']), 15);
});
it('should work with a mixture of numbers and strings', function () {
assert.equal(arraySum(['1', 2, '3', 4, '5']), 15);
});
it('should ignore non-numbers.', function () {
assert.equal(arraySum([1, 'foo', 2, 3, 4, {}, 5]), 15);
});