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.92 KB
/
totalIntegers.spec.js
File metadata and controls
50 lines (39 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
const totalIntegers = require('./totalIntegers');
describe('totalIntegers', () => {
test('Counts all integers in a simple array of only integers', () => {
expect(totalIntegers([1, 2, 3])).toBe(3);
});
test.skip('Ignores non-number values', () => {
expect(totalIntegers([1, 2, '3', 4])).toBe(3);
});
test.skip('Counts all integers in a plain object', () => {
expect(totalIntegers({ a: 1, b: '2', c: 3 })).toBe(2);
});
test.skip('Does not find any integers in nested empty arrays', () => {
expect(totalIntegers([[], [], []])).toBe(0);
});
test.skip('Counts integers in deeply nested arrays', () => {
expect(totalIntegers([[[[[[[[[[[[[[4]]]]]], 246]]]]]]]])).toBe(2);
});
test.skip('Counts negative integers', () => {
expect(totalIntegers([5, 7, -7, [45, -1, -0], [4, 7, -4, -4, -4, [777777, -45674]], [-5477654]])).toBe(14);
});
test.skip('Does not count non-integer numbers', () => {
expect(totalIntegers([5, 7.7, 7, [45, 1, 0], [4.0, 7, [7.77777, 4567.4]], [5477.654]])).toBe(7);
});
test.skip('Returns undefined for non-array/object arguments', () => {
expect(totalIntegers('2')).toBe(undefined);
expect(totalIntegers(() => {})).toBe(undefined);
expect(totalIntegers(42)).toBe(undefined);
expect(totalIntegers(NaN)).toBe(undefined);
});
test.skip('Does not count NaN as an integer', () => {
expect(totalIntegers([5, NaN, [NaN, NaN, 64], 4])).toBe(3);
});
test.skip('Counts all integers even with deeply nested containing multiple types', () => {
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('Counts all integers when nested arrays and objects are mixed together', () => {
expect(totalIntegers([4, 6, { a: 1, b: { a: [5, 10], b: 11 } }, 9])).toBe(7);
});
});