-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmaxSumSubarray.test.js
More file actions
46 lines (41 loc) · 1.34 KB
/
maxSumSubarray.test.js
File metadata and controls
46 lines (41 loc) · 1.34 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
40
41
42
43
44
45
46
const findMaxSumSubarray = require("./maximumSumSubarray.js");
describe("findMaxSumSubarray()", () => {
test("returns null if the argument passed in is not an array", () => {
const result = findMaxSumSubarray("test");
expect(result).toBeNull();
});
test("returns 0 if the array has no length", () => {
const result = findMaxSumSubarray([]);
expect(result).toBe(0);
});
test("returns 0 if all the numbers in the array are negative", () => {
const result = findMaxSumSubarray([-9, -4, -3, -2, -1, -10, -1234]);
expect(result).toBe(0);
});
test("returns the correct maximum sum subarray of a small array of numbers", () => {
// the maximum should be the sum of 7, 3, and 5
const result = findMaxSumSubarray([7, 3, 5, -10, -4, 5, 0, 4]);
expect(result).toBe(15);
});
test("returns the correct maximum sum subarray of a large array of numbers", () => {
// the maximum should be the sum of 123, 6, 8, and 546
const result = findMaxSumSubarray([
4,
6,
-1,
-4,
-15,
345,
3,
-13,
-5678,
-123,
123,
6,
8,
546,
0
]);
expect(result).toBe(683);
});
});