diff --git a/src/_Problems_/max-consecutive-1s/index.js b/src/_Problems_/max-consecutive-1s/index.js index 18a5058a..7720370c 100644 --- a/src/_Problems_/max-consecutive-1s/index.js +++ b/src/_Problems_/max-consecutive-1s/index.js @@ -22,3 +22,5 @@ function findMaxConsecutive1s(arr) { if (count> max) max = count; return max; } + +module.exports = { findMaxConsecutive1s }; diff --git a/src/_Problems_/max-consecutive-1s/max-consecutive-1s.test.js b/src/_Problems_/max-consecutive-1s/max-consecutive-1s.test.js new file mode 100644 index 00000000..e37abdae --- /dev/null +++ b/src/_Problems_/max-consecutive-1s/max-consecutive-1s.test.js @@ -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 によって変換されたページ (->オリジナル) /