Skip to content

Commit 1ff3d52

Browse files
committed
Add unit tests to Max Consecutive 1s problem
1 parent e7f1166 commit 1ff3d52

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { findMaxConsecutive1s } = require(".");
2+
3+
describe("Find maximum numbers of consecutive 1s", () => {
4+
it("returns 1 if there is only one number 1", () => {
5+
expect(findMaxConsecutive1s([1])).toEqual(1);
6+
});
7+
8+
it("return the appropriate count for a large array", () => {
9+
const largeArray = [0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1];
10+
expect(findMaxConsecutive1s(largeArray)).toEqual(5);
11+
});
12+
13+
it("returns count 0 if there is no number 1", () => {
14+
expect(findMaxConsecutive1s([0, 2, 3, 9, 0])).toEqual(0);
15+
});
16+
17+
it("does NOT count negative 1s", () => {
18+
expect(findMaxConsecutive1s([1, 1, 0, -1, -1, -1])).toEqual(2);
19+
});
20+
});

0 commit comments

Comments
 (0)