-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximumSubarray.test.js
More file actions
39 lines (33 loc) · 1.33 KB
/
Copy pathmaximumSubarray.test.js
File metadata and controls
39 lines (33 loc) · 1.33 KB
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
const maximumSubarray = require('./maximumSubarray');
describe('maximumSubarray', () => {
it('should return the correct range for positive numbers', () => {
const nums = [1, 2, 3, 4, 5];
const expectedRange = [0, 4];
expect(maximumSubarray(nums)).toEqual(expectedRange);
});
it('should return the correct range for negative numbers', () => {
const nums = [-1, -2, -3, -4, -5];
const expectedRange = [0, 0];
expect(maximumSubarray(nums)).toEqual(expectedRange);
});
it('should return the correct range for a mix of positive and negative numbers', () => {
const nums = [2, -1, 3, 4, -2, 1];
const expectedRange = [0, 3];
expect(maximumSubarray(nums)).toEqual(expectedRange);
});
it('should return the correct range when the maximum sum is at the end of the array', () => {
const nums = [1, 2, 3, -10, 4, 5];
const expectedRange = [4, 5];
expect(maximumSubarray(nums)).toEqual(expectedRange);
});
it('should return the correct range when the maximum sum is at the beginning of the array', () => {
const nums = [10, -2, -3, -4, -5];
const expectedRange = [0, 0];
expect(maximumSubarray(nums)).toEqual(expectedRange);
});
it('should return the correct range when the array contains only one element', () => {
const nums = [5];
const expectedRange = [0, 0];
expect(maximumSubarray(nums)).toEqual(expectedRange);
});
});