|
| 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