-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathmax-consecutive-1s.test.js
73 lines (53 loc) · 2.01 KB
/
max-consecutive-1s.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const findMaxConsecutive1s = require('.');
describe('Find max consecutive 1s', () => {
it('returns 0 for an empty array', () => {
const inputArr = [];
const expected = 0;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('returns 0 for an array containing a single 0', () => {
const inputArr = [0];
const expected = 0;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('returns 1 for an array containing a single 1', () => {
const inputArr = [1];
const expected = 1;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('returns 1 for an array containing a single 1 and 0', () => {
const inputArr = [1, 0];
const expected = 1;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('returns 1 for an array containing a single 0 and 1', () => {
const inputArr = [0, 1];
const expected = 1;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('returns 1 for a large alternating array of 1s and 0s', () => {
const inputArr = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1];
const expected = 1;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('returns 5 for increasing groups of 1s (max 5)', () => {
const inputArr = [1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1];
const expected = 5;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('returns 5 for decreasing groups of 1s (max 5)', () => {
const inputArr = [1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1];
const expected = 5;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('returns 5 for an array of 5 1s', () => {
const inputArr = [1, 1, 1, 1, 1];
const expected = 5;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
it('skips 1s that are Strings', () => {
const inputArr = [1, 1, '1'];
const expected = 2;
expect(findMaxConsecutive1s(inputArr)).toEqual(expected);
});
});