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

Add unit tests to Max Consecutive 1s problem #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LeoSL wants to merge 1 commit into knaxus:master from LeoSL:add-test-to-max-consecutives-1s
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/_Problems_/max-consecutive-1s/index.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ function findMaxConsecutive1s(arr) {
if (count > max) max = count;
return max;
}

module.exports = { findMaxConsecutive1s };
20 changes: 20 additions & 0 deletions src/_Problems_/max-consecutive-1s/max-consecutive-1s.test.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { findMaxConsecutive1s } = require(".");

describe("Find maximum numbers of consecutive 1s", () => {
it("returns 1 if there is only one number 1", () => {
expect(findMaxConsecutive1s([1])).toEqual(1);
});

it("return the appropriate count for a large array", () => {
const largeArray = [0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1];
expect(findMaxConsecutive1s(largeArray)).toEqual(5);
});

it("returns count 0 if there is no number 1", () => {
expect(findMaxConsecutive1s([0, 2, 3, 9, 0])).toEqual(0);
});

it("does NOT count negative 1s", () => {
expect(findMaxConsecutive1s([1, 1, 0, -1, -1, -1])).toEqual(2);
});
});

AltStyle によって変換されたページ (->オリジナル) /