|
| 1 | +const totalIntegers = require('./totalIntegers'); |
| 2 | + |
| 3 | +describe('totalIntegers', () => { |
| 4 | + test('Works with a simple array of numbers', () => { |
| 5 | + expect(totalIntegers([1, 2, 3])).toBe(3); |
| 6 | + }); |
| 7 | + |
| 8 | + test.skip('Ignores non-integer values', () => { |
| 9 | + expect(totalIntegers([1, 2, '3', 4])).toBe(3); |
| 10 | + }); |
| 11 | + |
| 12 | + test.skip('Works with simple objects', () => { |
| 13 | + expect(totalIntegers({ a: 1, b: '2', c: 3 })).toBe(2); |
| 14 | + }); |
| 15 | + |
| 16 | + test.skip('Works with an empty nested array', () => { |
| 17 | + expect(totalIntegers([[], [], []])).toBe(0); |
| 18 | + }); |
| 19 | + |
| 20 | + test.skip('Works with a very nested array', () => { |
| 21 | + expect(totalIntegers([[[[[[[[[[[[[[4]]]]]], 246]]]]]]]])).toBe(2); |
| 22 | + }); |
| 23 | + |
| 24 | + test.skip('Works with negative numbers', () => { |
| 25 | + expect(totalIntegers([5, 7, -7, [45, -1, -0], [4, 7, -4, -4, -4, [777777, -45674]], [-5477654]])).toBe(14); |
| 26 | + }); |
| 27 | + |
| 28 | + test.skip('Works with floats', () => { |
| 29 | + expect(totalIntegers([5, 7.7, 7, [45, 1, 0], [4.0, 7, [7.77777, 4567.4]], [5477.654]])).toBe(7); |
| 30 | + }); |
| 31 | + |
| 32 | + test.skip('Only accepts arrays or objects', () => { |
| 33 | + expect(totalIntegers('2')).toBe(undefined); |
| 34 | + expect(totalIntegers(() => {})).toBe(undefined); |
| 35 | + expect(totalIntegers(42)).toBe(undefined); |
| 36 | + expect(totalIntegers(NaN)).toBe(undefined); |
| 37 | + }); |
| 38 | + |
| 39 | + test.skip('Works with NaN', () => { |
| 40 | + expect(totalIntegers([5, NaN, [NaN, NaN, 64], 4])).toBe(3); |
| 41 | + }); |
| 42 | + |
| 43 | + test.skip('Works with a nested array of all kinds of things', () => { |
| 44 | + 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); |
| 45 | + }); |
| 46 | + |
| 47 | + test.skip('Works with arrays containing objects containing integers', () => { |
| 48 | + expect(totalIntegers([4, 6, { a: 1, b: { a: [5, 10], b: 11 } }, 9])).toBe(7); |
| 49 | + }); |
| 50 | +}); |
0 commit comments