forked from TheOdinProject/javascript-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtotalIntegers.spec.js
More file actions
50 lines (39 loc) · 1.78 KB
/
totalIntegers.spec.js
File metadata and controls
50 lines (39 loc) · 1.78 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
const totalIntegers = require('./totalIntegers');
describe('totalIntegers', () => {
test('Works with a simple array of numbers', () => {
expect(totalIntegers([1, 2, 3])).toBe(3);
});
test.skip('Ignores non-integer values', () => {
expect(totalIntegers([1, 2, '3', 4])).toBe(3);
});
test.skip('Works with simple objects', () => {
expect(totalIntegers({ a: 1, b: '2', c: 3 })).toBe(2);
});
test.skip('Works with an empty nested array', () => {
expect(totalIntegers([[], [], []])).toBe(0);
});
test.skip('Works with a very nested array', () => {
expect(totalIntegers([[[[[[[[[[[[[[4]]]]]], 246]]]]]]]])).toBe(2);
});
test.skip('Works with negative numbers', () => {
expect(totalIntegers([5, 7, -7, [45, -1, -0], [4, 7, -4, -4, -4, [777777, -45674]], [-5477654]])).toBe(14);
});
test.skip('Works with floats', () => {
expect(totalIntegers([5, 7.7, 7, [45, 1, 0], [4.0, 7, [7.77777, 4567.4]], [5477.654]])).toBe(7);
});
test.skip('Only accepts arrays or objects', () => {
expect(totalIntegers('2')).toBe(undefined);
expect(totalIntegers(() => {})).toBe(undefined);
expect(totalIntegers(42)).toBe(undefined);
expect(totalIntegers(NaN)).toBe(undefined);
});
test.skip('Works with NaN', () => {
expect(totalIntegers([5, NaN, [NaN, NaN, 64], 4])).toBe(3);
});
test.skip('Works with a nested array of all kinds of things', () => {
expect(totalIntegers([NaN, [[{}], 555 ], '444', [], 74.0, undefined, [[() => {}], [4], Infinity, [[[], -44.0], [null, '-4'], NaN [[]], 6]], () => {}, [[], [-Infinity, ['4'], [4.7, -46.7], NaN]]])).toBe(5);
});
test.skip('Works with arrays containing objects containing integers', () => {
expect(totalIntegers([4, 6, { a: 1, b: { a: [5, 10], b: 11 } }, 9])).toBe(7);
});
});