Skip to content

Commit 49da653

Browse files
committed
feat/ add tests
1 parent bdce415 commit 49da653

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
const totalIntegers = require('./totalIntegers-solution');
22

33
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);
86
});
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);
1428
});
1529
});

0 commit comments

Comments
 (0)