|
1 | 1 | const totalIntegers = require('./totalIntegers-solution'); |
2 | 2 |
|
3 | 3 | describe('totalIntegers', () => { |
4 | | - test('First test description', () => { |
5 | | - // Replace this comment with any other necessary code, and update the expect line as necessary |
6 | | - |
7 | | - expect(totalIntegers()).toBe(''); |
| 4 | + test('Works with an empty nested array', () => { |
| 5 | + expect(totalIntegers([[], [], []])).toBe(0); |
8 | 6 | }); |
9 | | - |
10 | | - test('Second test description', () => { |
11 | | - // Replace this comment with any other necessary code, and update the expect line as necessary |
12 | | - |
13 | | - expect(totalIntegers()).toBe(''); |
| 7 | + test('Works with a very nested array', () => { |
| 8 | + expect(totalIntegers([[[[[[[[[[[[[[4]]]]]], 246]]]]]]]])).toBe(2); |
| 9 | + }); |
| 10 | + test('Works with negative numbers', () => { |
| 11 | + expect(totalIntegers([5, 7, -7, [45, -1, -0], [4, 7, -4, -4, -4, [777777, -45674]], [-5477654]])).toBe(14); |
| 12 | + }); |
| 13 | + test('Works with floats', () => { |
| 14 | + expect(totalIntegers([5, 7.7, 7, [45, 1, 0], [4.0, 7, [7.77777, 4567.4]], [5477.654]])).toBe(11); |
| 15 | + }); |
| 16 | + test('Only accepts arrays', () => { |
| 17 | + expect(totalIntegers('2')).toBe(undefined); |
| 18 | + expect(totalIntegers({})).toBe(undefined); |
| 19 | + expect(totalIntegers(() => {})).toBe(undefined); |
| 20 | + expect(totalIntegers(42)).toBe(undefined); |
| 21 | + expect(totalIntegers(NaN)).toBe(undefined); |
| 22 | + }); |
| 23 | + test('Works with NaN', () => { |
| 24 | + expect(totalIntegers([5, NaN, [NaN, NaN, 64], 4])).toBe(3); |
| 25 | + }); |
| 26 | + test('Works with a nested array of all kinds of things', () => { |
| 27 | + 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); |
14 | 28 | }); |
15 | 29 | }); |
0 commit comments