Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb7e5a9

Browse files
Merge pull request #27 from narsaynorath/add_max_consecutive_1s_tests
Add unit tests for findMaxConsecutive1s
2 parents e7f1166 + ffe947b commit fb7e5a9

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

β€Žsrc/_Problems_/max-consecutive-1s/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ function findMaxConsecutive1s(arr) {
2222
if (count > max) max = count;
2323
return max;
2424
}
25+
26+
module.exports = findMaxConsecutive1s;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const findMaxConsecutive1s = require('.');
2+
3+
describe('Find max consecutive 1s', function() {
4+
it('returns 0 for an empty array', function() {
5+
const inputArr = [];
6+
const expected = 0;
7+
8+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
9+
});
10+
11+
it('returns 0 for an array containing a single 0', function() {
12+
const inputArr = [0];
13+
const expected = 0;
14+
15+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
16+
});
17+
18+
it('returns 1 for an array containing a single 1', function() {
19+
const inputArr = [1];
20+
const expected = 1;
21+
22+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
23+
});
24+
25+
it('returns 1 for an array containing a single 1 and 0', function() {
26+
const inputArr = [1, 0];
27+
const expected = 1;
28+
29+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
30+
});
31+
32+
it('returns 1 for an array containing a single 0 and 1', function() {
33+
const inputArr = [0, 1];
34+
const expected = 1;
35+
36+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
37+
});
38+
39+
it('returns 1 for a large alternating array of 1s and 0s', function() {
40+
const inputArr = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1];
41+
const expected = 1;
42+
43+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
44+
});
45+
46+
it('returns 5 for increasing groups of 1s (max 5)', function() {
47+
const inputArr = [1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1];
48+
const expected = 5;
49+
50+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
51+
});
52+
53+
it('returns 5 for decreasing groups of 1s (max 5)', function() {
54+
const inputArr = [1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1];
55+
const expected = 5;
56+
57+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
58+
});
59+
60+
it('returns 5 for an array of 5 1s', function() {
61+
const inputArr = [1, 1, 1, 1, 1];
62+
const expected = 5;
63+
64+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
65+
});
66+
67+
it('skips 1s that are Strings', function() {
68+
const inputArr = [1, 1, "1"];
69+
const expected = 2;
70+
71+
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
72+
});
73+
});
74+

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /